我在Action Bar中遇到问题。那么为什么我在Action Bar中创建Button 它只会崩溃从不显示图标。这是我的菜单
<item
android:id="@+id/action_name"
android:icon="@drawable/icon_home"
android:title="Home"
app:showAsAction="ifRoom"
android:orderInCategory="0"/>
答案 0 :(得分:0)
试试,
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="schemas.android.com/apk/res/android"
xmlns:app="schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_name"
android:icon="@drawable/icon_home"
android:title="Home"
app:showAsAction="always"
android:orderInCategory="1" /> </menu>
和
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.action_name:
//your code//
return true;
default:
return super.onOptionsItemSelected(item);
}
}