2015-05-22 58 views
9

我開始開發一個新應用程序,並且正在試圖給它一個材質設計外觀。爲此,我使用v7支持兼容性。在support.v7.widget.toolbar上隱藏應用程序標題

在應用程序的一些活動中,我需要工具欄不顯示應用程序標題,我不知道如何,但它默認顯示。在這些活動中,我在工具欄的右側有一個textview,它的作用就像一個按鈕,在那裏我實現了traex的RippleEffect

所以,基本上我的問題是,我怎麼能隱藏應用程序的標題從工具欄?因爲即使我做的:

toolbar.setTitle(""); 

toolbar.setTitle(null); 

它將繼續顯現。

這是我的代碼:

自定義工具欄的XML [toolbar_intro.xml]:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    xmlns:ripple="http://schemas.android.com/apk/res-auto" 
    xmlns:app="http://schemas.android.com/tools" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

    <com.andexert.library.RippleView 
     android:id="@+id/more" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_gravity="right" 
     android:layout_marginRight="40dp" 
     ripple:rv_centered="false" 
     app:rv_rippleDuration="1"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/toolbar_text" 
      android:textColor="@color/White" 
      android:textStyle="bold" 
      android:textSize="25sp" 
      android:text="Next"/> 
    </com.andexert.library.RippleView> 
</android.support.v7.widget.Toolbar> 

這是我包括佈局工具欄:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar_intro" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      ... 

    </RelativeLayout> 
</LinearLayout> 

這是活動:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.intro_wellcome); 

    toolbar= (Toolbar) findViewById(R.id.toolbar); 
    if (toolbar != null) { 
     setSupportActionBar(toolbar); 
     toolbar.setTitle(""); 
    } 

    TextView toolbar_text = (TextView) toolbar.findViewById(R.id.toolbar_text); 
    toolbar_text.setText(R.string.next); 

    ... 

} 

此外,這是我已經實現了風格:

<style name="MaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> 

回答

32

使用

getSupportActionBar().setDisplayShowTitleEnabled(false); 
+0

就這麼簡單!謝謝! – masmic

+1

沒問題。確保你檢查空指針,以避免警告:) –

+0

你可以嘗試爲toolbar.setTitle(「」); –

2

使用

getSupportActionBar().setDisplayShowTitleEnabled(false);

setContentView()setSupportActionBar()功能。

0
getSupportActionBar.setTitle(""); 
+0

雖然此代碼段可能會解決問題,但[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 –

相關問題