1

プロジェクトで actionbarsherlock を使用しています

現在のアクティビティに応じてアクションバーのスタイルを変えたい

アクティビティごとにカスタム アクションバー スタイルを定義するにはどうすればよいですか?

4

1 に答える 1

1

oncreate でこれを試してみてください。

    setContentView(R.layout.mobile_change);
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setCustomView(R.layout.header);
    getSupportActionBar().setBackgroundDrawable(
            new ColorDrawable(Color.parseColor("#5B5292")));
    TextView txt = (TextView) findViewById(R.id.tv_title_header);
    Typeface font = Typeface.createFromAsset(getAssets(), "georgia.ttf");
    txt.setText("CHANGE MOBILE NO.");
    txt.setTextSize(13);
    txt.setTypeface(font);

ヘッダー レイアウトが必要な場合は、このコードを試してください。それ以外の場合は、必要に応じて任意のヘッダーを作成できます

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.4"
        android:gravity="center" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.2"
        android:gravity="center" >

        <TextView
            android:id="@+id/tv_title_header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center"
            android:singleLine="true"
            android:text=""
            android:textAllCaps="true"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.4"
        android:gravity="center"
        android:padding="2dp" >

        <ImageView
            android:id="@+id/iv_merchant_logo_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:maxHeight="50dp" />
    </LinearLayout>
</LinearLayout>

于 2013-09-02T13:12:56.757 に答える