Android的可点击的TextView与提示和图像开始搜索对话框和present选择的结果 [英] Android clickable TextView with hint and image to start search dialog and present selected result
本文介绍了Android的可点击的TextView与提示和图像开始搜索对话框和present选择的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在寻找一个例子,说明如何,我可以实现一个可点击的TextView启动了Android默认的搜索对话框并显示选择的结果一致。
I'm searching for an example that shows how I can implement a clickable textview that starts the Android default search dialog and displays a selected result line.
它应该有相同的行为,并设计在Android上的谷歌地图操作栏上的搜索栏(左如放大镜玻璃图标,搜索提示,如果TextView的是空的,点击开始定义的搜索对话框通过一个可搜索的条目):
It should have the same behaviour and design as the search field in the Google Maps action bar on Android (e. g. magnifier glass icon on the left, a "Search" hint if the textview is empty, a click starts the search dialog defined by a searchable entry):
推荐答案
这是自定义的的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"
/>
结果
Result
这篇关于Android的可点击的TextView与提示和图像开始搜索对话框和present选择的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文