android - Center TextView in custom ActionBar horizontally -


a want create custom actionbar app name in center of still aligned left. here xml of custom_actionbar.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:gravity="center"                 android:background="@color/transparent">          <textview             android:id="@+id/nav_bar_title"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerinparent="true"             android:background="@color/transparent"             android:singleline="true"             android:textcolor="@color/sue_green"             android:text="@string/app_name"             android:textappearance="?android:attr/textappearancelarge">         </textview>  </relativelayout> 

here on create of activity:

public class deviceoverviewactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setrequestedorientation(activityinfo.screen_orientation_full_sensor);          settheme(r.style.theme_sue);         setcontentview(r.layout.activity_device_overview);          final actionbar actionbar = getactionbar();         actionbar.setdisplayshowtitleenabled(false);         actionbar.setdisplayshowhomeenabled(false);         actionbar.setdisplayuselogoenabled(false);          layoutinflater inflator = (layoutinflater) .getsystemservice(context.layout_inflater_service);         view v = inflator.inflate(r.layout.custom_actionbar, null);          actionbar.setdisplayshowcustomenabled(true);         actionbar.setcustomview(v);     } ... } 

can advice doing wrong? thanks

change textviews width match_parent , apply android:gravity="center_horizontal"


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -