ActionBarSherlock custom view location in landscape mode
I want to add a custom view to the actionbar in my application instead of
the default title and icon. The problem is that in landscape mode, the
custom view appears to right of the tabs. How can I place the custom view
on the left side?
Below are the custom view layout file and code where I add it to the
actionbar
<?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="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:textSize="30sp"
android:paddingLeft="5dp"
android:layout_alignParentLeft="true"
android:paddingRight="5dp"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:id="@+id/tvTextIcon"/>
<TextView
android:id="@+id/tvTextTitle"
android:layout_width="wrap_content"
android:gravity="center"
android:maxLines="1"
android:ellipsize="end"
android:paddingBottom="2dp"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tvTextIcon" />
</RelativeLayout>
Java Class:
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(title);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setIcon(android.R.color.transparent);
actionBar.setCustomView(R.layout.actionbar_layout);
TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
tvTitle.setText(title);
TextView tvIconText = (TextView) findViewById(R.id.tvIconText);
tvIconText.setText(iconText);
No comments:
Post a Comment