SearchView元素没有用于更改文本颜色的任何属性.默认文本颜色为黑色,不适用于我们的深色背景.有没有办法改变文本的颜色而不诉诸黑客?
我发现这个类似的问题与更改文本大小有关,但到目前为止,它没有任何答案: 如何设置SearchView TextSize?
有人知道如何更改appcompat SearchView的文本颜色吗?我花了2个小时从SO那里尝试了几个建议,但都没有.
这是我的代码:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:espacios="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/layer_switcher_button"
android:icon="@drawable/b_categorias"
android:title="@string/menu_layer_switcher_title"
espacios:showAsAction="ifRoom|collapseActionView"/>
<item
android:id="@+id/action_search"
android:icon="@drawable/b_buscar"
android:title="@string/menu_search_title"
espacios:actionViewClass="android.support.v7.widget.SearchView"
espacios:showAsAction="ifRoom|collapseActionView"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
在我的活动中我有这个:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
menuItem layerSwitcher = menu.findItem(R.id.layer_switcher_button);
layerSwitcher.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
onLayerSwitcherButtonClicked();
return false;
}
});
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
LinearLayout ll = (LinearLayout) searchView.getChildAt(0);
TextView textView = (TextView) ll.getChildAt(0);
textView.setTextColor(R.color.white);
}
Run Code Online (Sandbox Code Playgroud) 是否有任何api设置限制否.SearchView中的字符?
SearchView我在 中有以下实现xml,文本条目已从顶部剪切,如下图所示。无论textSize我放什么,都不会改变。
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="32dp"
android:gravity="center_vertical"
android:layout_marginTop="10dp">
<SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="12sp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)