2017-10-26 23 views
2

나는 메뉴에서 다시 이벤트를 잡는 방법을 알고하지 않습니다메뉴에서 뒤로 이벤트를 어떻게 잡을 수 있습니까?

enter image description here

내가 이벤트를 잡으려면 의미 누를 때 다시 button 화면의 왼쪽 상단에. 여기

메뉴의 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> 

감사합니다!

+1

[Android 구현 방법 ActionBar back button?] (https://stackoverflow.com/questions/10108774/how-to-implement-the-android-actionbar-back-button) –

+0

아니요, 내 작업 표시 줄은 항목을 길게 클릭했을 때만 표시됩니다. 다중 선택. – VinceMedi

답변

4

사용 경우 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 
1

사용 android.R.id.home이 쓸 수

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    if (item.getItemId() == android.R.id.home) { 
     //Navigation Back Pressed 
    } 
    return super.onOptionsItemSelected(item); 
}