Search code examples
androidactionbarsherlock

how to set Text in actionBar Sherlock programmatically


Below is my application header and I want to set current date-time in "DD/MM" place. How can I do this programmatically ? I am using actionBarSherlock

enter image description here

This is how I have set the background:

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
    </style>

    <style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
        <item name="android:background">@drawable/abs_bg</item>
        <item name="background">#ffffff</item>
</style>

Solution

  • If you don't need to use any option menu or any other actionBarSherlock functionality, then there is no need to this library. You can use any theme with NoTitleBar and create a custom RelativeLayout t create the header.

    styles.xml:

    <style name="AppTheme" parent="android:Theme.Light.NoTitleBar">
     <!--Anything -->
    </style>
    

    Your layout.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
    
        <RelativeLayout android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:background="#6ccff6">
    
            <ImageView
                android:id="@+id/logo"
                android:adjustViewBounds="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/abs_bg" />
    
            <TextView
                android:id="@+id/date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:textColor="@android:color/white"
                android:text="July 25"
                android:textAppearance="?android:attr/textAppearanceMedium" />
    
        </RelativeLayout>
        <!-- Put any other layout/view here -->
    
    </LinearLayout>