2016-04-26 30 views
0

我有一個菜單項,帶有圖標和文本。我正在使用Appcompat v7庫。菜單項不顯示文本,即使showAsAction設置爲withText | always或反之亦然。appcompat v7 23 - 帶app的菜單項:showAsAction =「withText | always」不顯示標題

menu.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <item 
     android:id="@+id/action_next" 
     android:icon="@drawable/ic_action_registration_next" 
     android:orderInCategory="0" 
     android:title="Next" 
     app:showAsAction="always" /> 
</menu> 

我嘗試了這些組合的showAsAction。

always|withText 
withText|always 
ifRoom|withText 

工具欄只顯示圖標,但不顯示標題。我如何顯示標題和圖標?請看下圖:

enter image description here

讓我知道你需要什麼。

+2

我相信它是文本或帶有菜單xml的圖標。如果你同時需要,你需要工具欄中的自定義佈局 –

+0

@ cricket_007,謝謝你的信息。 –

回答

1

操作欄/工具欄實現考慮將withText作爲請求,而不是命令。他們將決定是否顯示文本是否有足夠的空間。在這種情況下,appcompat-v7顯然認爲沒有足夠的空間。如果您嘗試將此設備旋轉到橫向模式或在平板電腦上進行測試,您應該看到標題出現,如果您的app:showAsAction屬性中包含withText

+0

Okie ..明白了。我可以在橫向模式下看到它。有沒有解決方法(不創建工具欄中的視圖),我強制使文字和圖標在縱向模式下可見,因爲我只有一個菜單項。 –

+0

@VamsiChalla:不是我所知道的。請記住,如果您支持多種語言,但您可能有空間容納某些語言的文本,則可能無法使用其他語言。我建議簡單地允許操作欄/工具欄實現做出決定。 – CommonsWare

+0

明白了,謝謝... –