Lena Bru
Lena Bru

Reputation: 13947

how to create custom styles for the actionbar sherlock per activity

I am using actionbarsherlock in my project

and I want to style the actionbar differently depending on the activity I am currently in

how do I define a custom actionbar style, per activity?

Upvotes: 1

Views: 285

Answers (1)

sarabu
sarabu

Reputation: 521

Try this in oncreate it will work

    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);

If you need the header layout try this code or else you can create any header as your wish

<?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>

Upvotes: 1

Related Questions