【发布时间】:2014-06-27 14:26:46
【问题描述】:
由于某种原因,我无法让我的按钮出现在操作栏上。我已经在 /res/menu 中的 XML 文件中定义了它,并对其进行了膨胀并监听动作。该图标位于 /res/drawable-hdpi 中。在 logcat 中没有显示任何有趣的内容。 :(
XML:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/logout"
android:icon="@drawable/logout"
android:title="Logout"
android:orderInCategory="100"
android:showAsAction="always" />
</menu>
主要活动中的代码:
public class MainActivity extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.logout:
//logout code
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//rest of app
}
我按照这个问题来解决我最初的问题,但它没有帮助。 How to add button in ActionBar(Android)?
【问题讨论】: