Android 我怎样才能从菜单中捕捉背面事件?
我不知道如何从菜单中捕捉背面事件: 我的意思是我想在按下屏幕左上角的后退Android 我怎样才能从菜单中捕捉背面事件?,android,android-menu,Android,Android Menu,我不知道如何从菜单中捕捉背面事件: 我的意思是我想在按下屏幕左上角的后退按钮时捕捉事件 下面是菜单的xml文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
按钮时捕捉事件
下面是菜单的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/ActionModeMenu">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox
android:id="@+id/context_menu_select_tweet_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:onClick="onSelectAllTweet" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:theme="@style/ActionModeMenuSubtitle"
android:text="@string/menu_tweet_select_all_text"/>
</LinearLayout>
<TextView
android:id="@+id/context_menu_select_tweet_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="10dp"
android:theme="@style/ActionModeMenuTitle"/>
</LinearLayout>
谢谢 使用android.R.id.home
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
}
return super.onOptionsItemSelected(item);
}
如果要更改后向箭头的图像,可以在OnCreate
方法中写入
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.mipmap.back_to); // change the image
使用android.R.id.home
返回导航按钮
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
//Navigation Back Pressed
}
return super.onOptionsItemSelected(item);
}
可能重复“否,我的操作栏”仅在我长时间单击多项选择的项目时显示。