2015-05-15 158 views
6

我想將Android上的三點按鈕更改爲其他按鈕,即「添加」按鈕。怎麼做?我已經改變了在我的繪圖中設置按鈕,但它保持提示三個點按鈕。如何將android上的三個點按鈕更改爲其他按鈕

感謝

+1

如果粘貼你的代碼的人也許能夠幫助你更快。 – Sameer

+0

請在這裏添加一些圖片什麼想要實現。然後你會得到更快的幫助。因爲你說的很難理解。 –

+0

[如何更改操作欄中的選項菜單圖標?](https://stackoverflow.com/questions/26300480/how-to-change-option-menu-icon-in-the-action-bar) – Nikolaus

回答

16

對不起,我不能答覆的評論,但我猜你想改變動作條溢出菜單圖標。如果是這樣,你可以在styles.xml

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item> 
</style> 

<!-- Style to replace actionbar overflow icon. set item 'android:actionOverflowButtonStyle' in AppTheme --> 
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow"> 
    <item name="android:src">@drawable/ic_launcher</item> 
</style> 

原帖:How to change option menu icon in the action bar?

6
//just edit menu.xml file  
//add icon for item which will change default setting icon 
//add sub menus 


///menu.xml file 


    <item 
      android:id="@+id/action_settings" 
      android:orderInCategory="100" 
      android:title="@string/action_settings" 
      android:icon="@drawable/your_icon" 
      app:showAsAction="always" > 

      <menu> 

       <item android:id="@+id/action_menu1" 
        android:icon="@android:drawable/ic_menu_preferences" 
        android:title="menu setting" /> 

       <item android:id="@+id/action_menu2" 
        android:icon="@android:drawable/ic_menu_help" 
        android:title="help" /> 

      </menu> 
     </item> 
4

如果你想添加的,而不是3點的其他圖標然後就創建一個類似下面的代碼menu.xml文件:

<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_add" 
    android:title="Add" 
    app:showAsAction="always" 
    android:icon="@drawable/ic_add" /> 
</menu> 

注: 唐不要用android:showAsAction。 使用app:showAsAction

+0

爲什麼你建議應用程序而不是android? 這是解決方案,但我不明白爲什麼。 –

3

對不起,我沒有足夠的知名度,無法發表評論。這裏是最好的答案,我發現,它的一行代碼:

myToolbar.setOverflowIcon(ContextCompat.getDrawable(getApplicationContext(),R.drawable.my_drawable)); 

的鏈接,原來答案就在這裏: https://stackoverflow.com/a/35790470/4575772

+1

請不要發佈鏈接只回答其他堆棧溢出問題。相反,投票/標誌以重複的方式關閉,或者,如果問題不重複,*定製針對此特定問題的答案。* –

相關問題