2016-12-25 89 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(); 
相關問題