如何为每个活动的操作栏sherlock创建自定义样式

时间:2013-09-02 12:40:36

标签: android styles actionbarsherlock

我在项目中使用actionbarsherlock

我希望根据我当前的活动

对动作栏进行不同的设置

如何为每个活动定义自定义操作栏样式?

1 个答案:

答案 0 :(得分: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>