1

ABSActionBarでカスタム レイアウトを使用しています。

    View abview = getLayoutInflater().inflate(R.layout.custombar, null);
    getSupportActionBar().setCustomView(abview);

現在、ホーム/アップボタンはありません。私はすでに試しました:

getSupportActionBar().setHomeButtonEnabled(true); 

でカスタム ビューを使用する場合ActionBar、アップ ボタンをすべて自分で処理する必要がありますか?

4

3 に答える 3

2

ActionBar (ActionBarsherlock) でカスタム ビューを使用する場合は、すべての actionBar を自分で管理する必要があります。そのため、ActionBar を保持し、xml をバックグラウンドに設定するか、特定の要素に customview を設定することをお勧めします。カスタム アクションバーで何をしたいですか?

于 2013-03-06T10:00:57.460 に答える
1

次のように、アクションバーにカスタムアクションビューを追加できます。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (DEBUG_MODE) {
        Log.d(TAG, "onCreateOptionsMenu()");
    }
    getSupportMenuInflater().inflate(R.menu.menu_generic, menu);

    // Progress
    final MenuItem progress = menu.findItem(R.id.menu_progress);
    progress.setActionView(R.layout.action_view_progress);

    mProgressText = (TextView) progress.getActionView().findViewById(R.id.total_achievement_text);

    return super.onCreateOptionsMenu(menu);
}

menu_genric.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/menu_progress"
    android:showAsAction="always"/>
</menu>

その後、mProgressTextを参照して数を増やすことができます

于 2013-03-07T13:49:46.540 に答える