【问题标题】:How to change the name of the toolbar for each activity in Android Studio?如何更改 Android Studio 中每个活动的工具栏名称?
【发布时间】:2018-08-29 18:51:12
【问题描述】:

我想知道如何更改每个 Activity 的工具栏名称。而且我想知道如何让每个名字居中! 谢谢!

【问题讨论】:

  • android:title....
  • @SantanuSur 是的,但是我必须在哪里写呢?

标签: java android json xml


【解决方案1】:

试试这个

<android.support.v7.widget.Toolbar
   android:id="@+id/toolbar_top"
   android:layout_height="wrap_content"
   android:layout_width="match_parent"
   android:minHeight="?attr/actionBarSize"
   android:background="@color/action_bar_bkgnd"
   app:theme="@style/ToolBarTheme" >


 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Toolbar Title"
    android:layout_gravity="center"
    android:id="@+id/toolbar_title" />


</android.support.v7.widget.Toolbar>

在你的活动中

Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);

用于操作栏

setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);

关于每个活动

【讨论】:

  • 是的,但它只为所有活动设置了一个名称,我希望为每个活动设置不同的名称!
  • 你是指Toolbar还是ActionBar?
  • 工具栏。不是工具栏 (android.support.v7.widget) 只是工具栏(android.widget)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-03
  • 1970-01-01
相关资源
最近更新 更多