我想在我的应用程序中自定义搜索 View 小部件的“edittext”。我想以编程方式设置其背景可绘制对象。我还想以编程方式添加标志 android:imeOptions="flagNoExtractUi"
以便在横向模式下,软键盘只会覆盖屏幕的一半。
有人知道如何在搜索 View “edittext”上进行自定义吗?
最佳答案
我就是这样做的。我研究了操作栏 sherlock 库中的 abs_search_view.xml
并了解到 R.id.search_plate
代表一个 LinearLayour。 LinearLayout 的第一个子项是一个 View ,其类是 com.actionbarsherlock.widget.SearchView$SearchAutoComplete
。所以我检索了第一个 child 并将其转换为 com.actionbarsherlock.widget.SearchView.SearchAutoComplete
,进行了空检查,然后使用 searchText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI)< 设置了 IME 选项
正如 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));
}
关于android - 以编程方式自定义 SearchView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19357842/