Обычай EditText
с составной прорисовкой
public class SearchEditText extends EditText {
private boolean mMagnifyingGlassShown = true;
private Drawable mMagnifyingGlass;
public SearchEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mMagnifyingGlass = getCompoundDrawables()[0];
}
/**
* Conditionally shows a magnifying glass icon on the left side of the text field
* when the text it empty.
*/
@Override
public boolean onPreDraw() {
boolean emptyText = TextUtils.isEmpty(getText());
if (mMagnifyingGlassShown != emptyText) {
mMagnifyingGlassShown = emptyText;
if (mMagnifyingGlassShown) {
setCompoundDrawables(mMagnifyingGlass, null, null, null);
} else {
setCompoundDrawables(null, null, null, null);
}
return false;
}
return super.onPreDraw();
}
и xml
<view
class="com.tr.search.SearchEditText"
android:id="@+id/search_src_text"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1.0"
android:singleLine="true"
android:ellipsize="end"
android:hint="@string/search_bar_hint"
android:drawableLeft="@drawable/magnifying_glass"
android:freezesText="true"
/>
Результат