如何在Android中更改操作栏中的设置徽标?
我想将如何在Android中更改操作栏中的设置徽标?,android,xml,menu,Android,Xml,Menu,我想将设置徽标更改为搜索徽标。我尝试在xml中进行以下更改,但似乎不起作用。有人能建议我做什么吗 我的xml如下所示: <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_settings" android:orderInCategory="100" android:showAsAction="never"
设置
徽标更改为搜索
徽标。我尝试在xml中进行以下更改,但似乎不起作用。有人能建议我做什么吗
我的xml如下所示:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:icon="@android:drawable/btn_minus"
android:title="@android:string/search_go"/>
</menu>
如果您正在使用操作栏,请使用此选项 1) 转到: 2) 下载“操作栏图标包” 3) 将ic_action_search放入可绘图目录中 4) 然后:
android:icon=“@drawable/ic\u action\u search”
如果不起作用,请尝试:您的应用程序名称:showAsAction=“always”
正如您在中看到的:
请注意,上面的showAsAction属性使用自定义命名空间
在标记中定义。这在使用任何XML时都是必要的
由支持库定义的属性,因为这些属性
在旧设备上的Android框架中不存在。所以你必须使用
您自己的命名空间作为
支持库
添加android:icon=“@drawable/ic\u menu\u some\u image”在更改可绘制图标后,图标不会更改尝试android:showAsAction=“always”。
<item
android:id="@+id/grid_default_search"
android:icon="@android:drawable/ic_menu_search"
android:title="search"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"
/>
<!-- other items or whatever -->
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.grid_default, menu);
SearchView searchView = (SearchView)menu.findItem(R.id.grid_default_search).getActionView();
searchView.setOnQueryTextListener(queryListener);
}
final private OnQueryTextListener queryListener = new OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
//Logic
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
//Logic
return false;
}
};