java - Android ActionBar does not show title that was set in code -


first, know there lot of address similar issues. i've scoured them all, , none of provided answers helping solve issue.

i cannot title (or button) appear on android.support.v7.widget.toolbar component. no matter i've tried.

i have android activity that looks (my_activity.xml):

<?xml version="1.0" encoding="utf-8"?> <layout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:bind="http://schemas.android.com/apk/res-auto">     <data>         <variable name="infos" type="com.mycompany.orm.adapters.listviewadapter"/>     </data>      <relativelayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical"         android:weightsum="10">          <android.support.v7.widget.toolbar             android:id="@+id/my_toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionbarsize"             android:background="@color/buttonbackground"             android:elevation="4dp"             android:logo="@drawable/ic_close_white_24dp" />          <listview             android:id="@+id/my_listview"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:divider="@color/windowbackground"             bind:items="@{infos.list}"/>     </relativelayout> </layout> 

and activity oncreate (myactivity.java):

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.my_activity);      toolbar toolbar = (toolbar) findviewbyid(r.id.my_toolbar);     if (toolbar != null) {         toolbar.settitle("my name here");   // never shows         setsupportactionbar(toolbar);          actionbar actionbar = getsupportactionbar();         if (actionbar != null) {             actionbar.setdisplayoptions(actionbar.display_show_title | actionbar.display_show_custom, actionbar.display_show_custom);             actionbar.settitle("hello world!");       // never shows             actionbar.setdisplayhomeasupenabled(true);             actionbar.sethomeasupindicator(r.drawable.ic_close_white_24dp);             actionbar.setdisplayshowtitleenabled(true);             actionbar.show();         }     } } 

but using code, see blank toolbar. never see text (either my name here or hello world!. however, if add line bind:title="testing" toolbar element of xml, see title appearing testing. however, want able manipulate of toolbar/actionbar, able in code.

does see might going wrong?

try set label in androidmanifest.xml

   <activity         android:name="yourpackagename.activity"         android:label="my name here"/> 

otherwise if want set programmatically

if using extends appcompatactivity class use

    toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);     toolbar.settitle("my name here");     this.getsupportactionbar().setdisplayhomeasupenabled(true); 

if using extends activity class use

  actionbar ab = getactionbar();   ab.settitle("my name here"); 

i suggest try use above solution work me .


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 -