2017-10-02 19 views
0

ActionBar에 메뉴가 텍스트로 표시되는지 (프로그래밍 방식으로) 어떻게 알 수 있습니까?ActionBar에 텍스트를 표시 할 수있는 경우에만 오버플로 메뉴를 표시하는 방법

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools"> 
    <item 
     android:id="@+id/action_cancel" 
     android:orderInCategory="100" 
     android:title="@string/action_cancel" 
     android:icon="@drawable/ic_cancel_24dp" 
     app:showAsAction="always|withText"/> 
    <item 
     android:id="@+id/action_clear" 
     android:orderInCategory="200" 
     android:title="@string/action_clear" 
     android:icon="@drawable/ic_clear_24dp" 
     app:showAsAction="always|withText"/> 
    <item 
     android:id="@+id/action_done" 
     android:orderInCategory="300" 
     android:title="@string/action_done" 
     android:icon="@drawable/ic_done_24dp" 
     app:showAsAction="always|withText"/> 
</menu> 

텍스트가 나는 메뉴가 메뉴
내가 ifRoom|withTextalways|withText 교체도 시도 으로하지만 두 경우 모두 유지하려면 표시되지 않으면, 내가 디버그를 위해 사용하고있는 장치는 아이콘 만이 아닌를 보여줍니다 본문.

답변

0

아이콘 + 텍스트가있는 항목을 넣는 사용자 지정 도구 모음 레이아웃을 사용하여 마지막으로 자원을 확보했습니다.

<TextView 
    android:id="@+id/action_cancel" 
    style="@style/ActionBarItem" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:drawableLeft="@drawable/ic_cancel" 
    android:text="@string/action_cancel"/> 

<TextView 
    android:id="@+id/action_clear" 
    style="@style/ActionBarItem" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:drawableLeft="@drawable/ic_clear" 
    android:text="@string/action_clear"/> 

<TextView 
    android:id="@+id/action_done" 
    style="@style/ActionBarItem" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:drawableLeft="@drawable/ic_done" 
    android:text="@string/action_done"/> 

private void setupActionBar() { 
    MyLog.pe(DEBUG, TAG, "+ setupActionBar()"); 
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 

final ActionBar actionBar = getSupportActionBar(); 
try { 
    assert actionBar != null; 
    actionBar.setDisplayShowTitleEnabled(false); 
    actionBar.setDisplayShowHomeEnabled(false); 
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    actionBar.setCustomView(R.layout.actionbar_cancel_clear_done); 

    final View customActionBarView = actionBar.getCustomView(); 
    customActionBarView.setLayoutParams(
      new Toolbar.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT, 
        ViewGroup.LayoutParams.MATCH_PARENT)); 
    customActionBarView.findViewById(R.id.action_cancel).setOnClickListener(this); 
    customActionBarView.findViewById(R.id.action_clear).setOnClickListener(this); 
    customActionBarView.findViewById(R.id.action_done).setOnClickListener(this); 
} catch (Exception e) { 
    MyLog.e(DEBUG, TAG, "SupportActionBar is null!"); 
} 


MyLog.px(DEBUG, TAG, "- setupActionBar()"); 

}