Change Custom Toolbar Text

淺唱寂寞╮ 提交于 2019-12-04 08:45:27

You forgot to set this:

 setSupportActionBar(toolbar);

and this:

getSupportActionBar().setDisplayShowTitleEnabled(false); 

YOUR ACTIVITY LIKE THIS:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarCustom);

setSupportActionBar(toolbar);

TextView textView = (TextView)toolbar.findViewById(R.id.toolbarTextView);
textView.setText("String");

getSupportActionBar().setDisplayShowTitleEnabled(false);
Shahriar Nasim Nafi

It will be like that. Java Code:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); //here toolbar is your id in xml
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("String"); //string is custom name you want

Here is how you change custom toolbar text in Android Kotlin:

First go to the Manifest file and i your activity add the line android:theme="@style/AppTheme.NoActionBar" in your activity tag

<activity
          android:name=".MainActivity"
          android:label="@string/app_name"
          android:theme="@style/AppTheme.NoActionBar">
 </activity>

Second go your Activity and add the following:

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setSupportActionBar(toolbar)
        toolbar.title = "My New Title"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!