Tuesday, 20 August 2013

EditText won't change TypeFace and Layout Background image onTextEdit

EditText won't change TypeFace and Layout Background image onTextEdit

When I change text in EditText, the layout background image and EditText
don't get changed.
Here's my Layout:
<RelativeLayout android:id="@+id/searchbox"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="@drawable/search" >
<EditText
android:id="@+id/editText1"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="40dp"
android:ems="10"
android:hint="Search"
android:imeOptions="flagNoExtractUi"
android:inputType="text"
android:lines="1"
android:minLines="1" />
</RelativeLayout>
and here's my activity code:
etSearch = (EditText) findViewById(R.id.editText1);
viewSearchBox = (RelativeLayout) findViewById(R.id.searchAppsBar);
etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int
arg2, int arg3) {
if (etSearch.getText() == null) {
viewSearchBox.setBackgroundResource(R.drawable.search);
} else {
viewSearchBox.setBackgroundResource(R.drawable.search_not_empty);
}
Typeface tfx = Typeface.createFromAsset(getAssets(),
"font_normal.ttf");
etSearch.setTypeface(tfx);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int
arg2, int arg3) {
Typeface tfx = Typeface.createFromAsset(getAssets(),
"font_italic.ttf");
etSearch.setTypeface(tfx);
}
@Override
public void afterTextChanged(Editable arg0) {
Typeface tfx = Typeface.createFromAsset(getAssets(),
"font_normal.ttf");
etSearch.setTypeface(tfx);
}
});
any way to get through this problem?

No comments:

Post a Comment