android - SherlockActionBar: How to adjust CustomView against actionBar -
question:
how can have title back?
here's screenshot (missing title):
actionbar setting:
actionbar actionbar = getsupportactionbar(); actionbar.settitle("my title"); actionbar.seticon(drawable.dropdown_user); view mlogoview = layoutinflater.from(this).inflate(r.layout.mlogoview, null); actionbar.setcustomview(mlogoview); actionbar.setdisplayshowcustomenabled(true); actionbar.setdisplayshowtitleenabled(true); actionbar.setdisplayhomeasupenabled(true);
mlogoview.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" > <imageview android:id="@+id/img_merchant" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:src="@drawable/infoflex"> </imageview> </relativelayout >
the first thing can think way fix try set
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right" >
to relativelayout
. because default in android every view added left right (if doesn't specify else in code).
and if doesn't work, add android:layout_width="90dip"
or other value depending on image , tests. second option more workaround, think work on devices.
edit:
as found there little problem using relativelayout
, custom views in actionbar, better option use linearlayout
, set layoutparams
via code. change xml :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/asus" /> </linearlayout >
and in mainactivity.class use :
import com.actionbarsherlock.app.actionbar.layoutparams; .... actionbar actionbar = getsupportactionbar(); actionbar.settitle("omg"); layoutparams lp = new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content, gravity.right | gravity.center_vertical); view customnav = layoutinflater.from(this).inflate(r.layout.img, null); // layout contains button. actionbar.setcustomview(customnav, lp); actionbar.setdisplayshowcustomenabled(true);
Comments
Post a Comment