我想自定义应用程序中搜索视图小部件中的“edittext”。我想以编程方式设置其背景可绘制对象。我还想通过编程方式添加标志
请问如何在搜索视图的“edittext”上进行这些自定义?
android:imeOptions="flagNoExtractUi"
,以便在横向模式下,软键盘仅覆盖屏幕的一半。请问如何在搜索视图的“edittext”上进行这些自定义?
android:imeOptions="flagNoExtractUi"
,以便在横向模式下,软键盘仅覆盖屏幕的一半。这是我所做的事情。我研究了ActionBarSherlock库中的abs_search_view.xml
,并了解到R.id.search_plate
代表一个LinearLayout。LinearLayout的第一个子元素是一个视图,其类为com.actionbarsherlock.widget.SearchView$SearchAutoComplete
。因此,我检索了第一个子元素,并将其强制转换为com.actionbarsherlock.widget.SearchView.SearchAutoComplete
,进行了空值检查,随后使用searchText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI)
设置了输入法选项,正如评论中Ahmend所建议的那样。希望这能对某些人有所帮助。
public static void styleSearchView(SearchView searchView, Context context) {
LinearLayout searchPlate = (LinearLayout) searchView
.findViewById(R.id.abs__search_plate);
// TODO
// searchPlate.setBackgroundResource(R.drawable.your_custom_drawable);
if (searchPlate != null)
((com.actionbarsherlock.widget.SearchView.SearchAutoComplete) searchPlate
.getChildAt(0))
.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
AutoCompleteTextView searchText = (AutoCompleteTextView) searchView
.findViewById(R.id.abs__search_src_text);
if (searchText != null)
searchText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
// TODO
// searchText.setHintTextColor(context.getResources().getColor(R.color.your_custom_color));
}