user3391455
user3391455

Reputation: 51

How to give more than one title in Action bar

I need to show two title:

Like this;

 Courses        UniversityName

I implemented custom . This is my action_bar.xml

      <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/uniname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/textView2"
        android:text="@string/app_name"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/app_name"
        android:textSize="18sp" />

</RelativeLayout>

In my activity class i called like this

 ActionBar actionBar = getActionBar();
 actionBar.setCustomView(R.layout.action_bar);
 actionBar.setSubtitle("sub-title"); 
 TextView uniName = (TextView) actionBar.getCustomView().findViewById(R.id.uniname);
 uniName.setText(prefs.getString("schoolName", ""));

Please help me. It didn't show subtitle

Upvotes: 0

Views: 50

Answers (1)

Nyx
Nyx

Reputation: 2243

Instead of

actionBar.setSubtitle("sub-title"); 

Do this

TextView subtitle = (TextView) actionBar.getCustomView().findViewById(R.id.textView2);
subtitle.setText("sub-title");

Upvotes: 2

Related Questions