android title won't show in toolbar

后端 未结 9 1515
粉色の甜心
粉色の甜心 2021-01-07 16:41

I have an xml that I use with so many activities with fragments file but my problem is that I can\'t display the text I want in the toolbar, I use that xml that way because

9条回答
  •  一生所求
    2021-01-07 16:54

    I did a custom action bar.

    Layout iguepardos_action_bar.xml with this code

    
    
    
        
    
    
    

    In my Class extended AppCompatActivity I had this:

    protected void onCreate(Bundle savedInstanceState) {
    .... 
    ....
    
    getSupportActionBar().setDisplayShowCustomEnabled(true); // is for specify use custom bar 
    getSupportActionBar().setCustomView(R.layout.iguepardos_action_bar);  // my custom layout
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Button for come back
    
    View mCustomView = getSupportActionBar().getCustomView(); // Set the view
    TextView TitleToolBar = (TextView) mCustomView.findViewById(R.id.toolbar_title); // find title control
    TitleToolBar.setText("The Title Show"); // Set the Title
    
    }
    

提交回复
热议问题