2016-12-25 96 views
0

我想在我的应用程序工具栏中显示特定文本,但它也始终显示应用程序的名称。我怎样才能摆脱应用程序名称,只有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> 
+1

在活动类getSupportActionBar()。setTitle(“Your Text”)中指定android:label =“You Text”。 –

回答

2

将标签添加到AndroidManifest.xml文件中的活动声明。

<activity 
     .... 
     android:label="Name of Your Screen" 
     .... 
    </activity> 
0

使用

<activity 
    android:label="blah-blah" /> 

将其设置在manifest文件。
或在代码toolbar.setTitle("blah-blah");
如果你设置你的ToolbarActionBar那么你可以拨打actionBar.setTitle("blah-blah");

1

如果你想有一个静态文本,在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(); 
相关问题