1

app : showAsAction = "always"를 사용하여 내 응용 프로그램의 메뉴 항목 설정 작업을 시도했습니다. 동일한 레이아웃을 사용하면 휴대 전화와 태블릿에서 작동합니다.두 창 모드에서 showAsAction = "always"가 작동하지 않습니다.

그러나 2 분할 창 레이아웃을 사용하면 항목이 작업 표시 줄에 표시되지 않지만 오버플로 메뉴에는 충분한 여유 공간이 있지만 표시됩니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    android:baselineAligned="false" 
    android:divider="?android:attr/dividerHorizontal" 
    android:orientation="horizontal" 
    android:showDividers="middle" 
    > 

    <fragment 
     android:id="@+id/gig_list" 
     android:name="de.nobodyknows.app.GigListFragment" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"/> 

    <FrameLayout 
     android:id="@+id/gig_detail_container" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="2" /> 

</LinearLayout> 

내 코드에서 I는 상세 단편으로 FrameLayout이 대체하는 콜백 방법을 사용 : 여기

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" > 

    <item 
     android:id="@+id/menu_item_maps" 
     android:icon="@drawable/ic_action_place" 
     android:orderInCategory="20" 
     android:title="@string/maps_menu_item" 
     app:showAsAction="always"> 
    </item> 
    <item 
     android:id="@+id/menu_item_event" 
     android:icon="@drawable/ic_action_event" 
     android:orderInCategory="30" 
     android:title="@string/menu_item_event" 
     app:showAsAction="always"> 
    </item> 
    <item 
     android:id="@+id/menu_item_share_gig" 
     android:orderInCategory="100" 
     android:title="@string/menu_item_share" 
     app:actionProviderClass="android.support.v7.widget.ShareActionProvider" 
     app:showAsAction="always"> 
    </item> 

</menu> 

두 창유리 배치도이다 : 여기

메뉴 XML이다

/** 
* Callback method from {@link GigListFragment.Callbacks} indicating that 
* the item with the given ID was selected. 
*/ 
@Override 
public void onItemSelected(Long id) { 
    if (mTwoPane) { 
     // In two-pane mode, show the detail view in this activity by 
     // adding or replacing the detail fragment using a 
     // fragment transaction. 
     Bundle arguments = new Bundle(); 
     arguments.putLong(GigDetailFragment.GIG_ID, id); 
     GigDetailFragment fragment = new GigDetailFragment(); 
     fragment.setArguments(arguments); 
     getSupportFragmentManager().beginTransaction() 
       .replace(R.id.gig_detail_container, fragment).commit(); 

    } else { 
     // In single-pane mode, simply start the detail activity 
     // for the selected item ID. 
     Intent detailIntent = new Intent(this, GigDetailActivity.class); 
     detailIntent.putExtra(GigDetailFragment.GIG_ID, id); 
     startActivity(detailIntent); 
    } 
} 

세부 조각은 위에 표시된 옵션 메뉴를 부풀립니다.

@Override 
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
     inflater.inflate(R.menu.detail, menu); 
    } 

이제 이러한 메뉴 항목은 새로운 활동이 시작될 때 전화 레이아웃에 잘 나타납니다. 그러나 첫 번째 액티비티에서 단편이 FrameLayout을 대체하면 메뉴 항목이 오버플로 메뉴에 표시됩니다. 나는 그것이 일어나는 이유를 알아낼 수 없다. 지원 라이브러리와 관련이 있습니까? 또는 파편이 어떻게 작동하는지에 관해 특별한 무엇인가?

도움 주셔서 감사합니다.

답변

1

좋아, 해결책을 찾았습니다.

내 활동이 ActionBarActivity을 확장하지 않았으므로 MenuItemCompat과 올바르게 작동하지 않습니다. 전화가 여전히 작동하는 이유는 해당 활동이 정확하게 ActionBarActivity으로 확장 되었기 때문입니다.

이 문제를 해결하기 위해 방금 두 창 활동으로 작동하는 활동의 수퍼 클래스를 ActionBarActivity으로 바 꾸었습니다.

관련 문제