簡體   English   中英

Android ActionBar操作標題在圖標前

[英]Android ActionBar Action title before icon

我正在尋找創建這樣的操作欄:

X取消--------------添加+

其中X和+是圖標。 因此,即時通訊使用getActionBar.setIcon設置X. home操作以設置Cancel標題。 ---------- stuf只是空白,一個帶有標題和圖標的操作,用於設置“添加”和“ +”,問題是默認情況下,該操作將圖標顯示在左側標題。 所以我有:

X取消-------------- +添加

有沒有辦法翻轉它? 或梅比,這樣做的更好方法。

我真的沒有動力為操作欄使用自定義布局,因為我認為我失去了操作項的功能...

這是菜單xml:

<item
    android:id="@+id/action_create_key"
    android:icon="@drawable/plus"
    android:title="@string/action_create"
    android:showAsAction="always|withText"/>

非常感謝您的時間和幫助...

使用庫存的ActionBar物品無法完成此操作。 你可以考慮使用完成/放棄自定義操作欄 ,它使用的兩個按鈕的操作欄自定義布局,替換“丟棄and完成for your取消and添加. If you are using the provided [DoneBarActivity source code][2], you'd want to change the right hand layout to use . If you are using the provided [DoneBarActivity source code][2], you'd want to change the right hand layout to use drawableRight rather than drawableLeft`來將圖標. If you are using the provided [DoneBarActivity source code][2], you'd want to change the right hand layout to use在文本的右側。

您為什么不希望對操作欄使用自定義布局? 您也可以將操作添加到自定義布局中的項目。 只需創建所需設計的自定義布局,然后使用以下代碼進行處理即可

final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.action_bar, null);
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(actionBarLayout);

    ImageView cancel = (ImageView) actionBarLayout.findViewById(R.id.cancel_icon);
    ImageView add = (ImageView) actionBarLayout.findViewById(R.id.add_icon);

    cancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

          //add your functionaity
        }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM