Android应用程序始终在工具栏中显示应用程序名称
问题描述:
我想在我的应用程序工具栏中显示特定文本,但它也始终显示应用程序的名称。我怎样才能摆脱应用程序名称,只有TextView
的文字?Android应用程序始终在工具栏中显示应用程序名称
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay"
android:fitsSystemWindows="true" >
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:fitsSystemWindows="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="The title I want to show"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
答
将标签添加到AndroidManifest.xml文件中的活动声明。
<activity
....
android:label="Name of Your Screen"
....
</activity>
答
使用
<activity
android:label="blah-blah" />
将其设置在manifest文件。
或在代码toolbar.setTitle("blah-blah");
如果你设置你的Toolbar
像ActionBar
那么你可以拨打actionBar.setTitle("blah-blah");
。
答
如果你想有一个静态文本,在AndroidManifest.xml
...
<activity
...
android:label="{YOUR_DESIRED_TEXT}">
...
</activity>
...
每个activity
标签设置android:label="{YOUR_DESIRED_TEXT}"
如果你想让它充满活力,你用this
getActionBar().setTitle("Hello world App");
// provide compatibility to all the versions
getSupportActionBar().setTitle("Hello world App");
但是,如果你完全搞定摆脱标题栏,您可以扩展Activity
而不是AppCompatActivity
或者您可以隐藏操作栏:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
在活动类getSupportActionBar()。setTitle(“Your Text”)中指定android:label =“You Text”。 –