<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_search"
android:icon="@drawable/search"
appcompat:actionViewClass="android.support.v7.widget.SearchView"
appcompat:showAsAction="ifRoom"
android:title="Search"/>
</menu>
我想更改右上角的search image,当前它是黑色,我想将其更改为橙色
最佳答案
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_notifications, menu);
this.menu = menu;
super.onCreateOptionsMenu(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_clear_all) {
showToast("Clear All");
return true;
}
return super.onOptionsItemSelected(item);
}
在res> menu下创建xml文件。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".YourActivityName" >
<item
android:id="@+id/action_clear_all"
android:title="@string/noti_clear_all"
android:icon="@drawable/ic_clear_all"
android:orderInCategory="100"
app:showAsAction="ifRoom" />
</menu>