2017-07-19 16 views
3

我在每個活動中都在使用我的Android應用Theme.AppCompat.Light.NoActionBar這個主題我的項目名稱即label標記名稱Application標籤出現在每個Android活動中,但在它沒有發生但最近發生。如果我刪除標籤,則會顯示包名稱而不是標題。Android應用標籤名稱無處不在

究竟發生了什麼?

我知道有幾種方法可以修復它,但是告訴我我錯在哪裏以及發生了什麼?這是一個錯誤嗎?

我提到前面的回答Android Application Name Appears as Activity Name和嘗試,但仍然沒有工作,所以這是我的manifest.xml

<application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".Activity2"></activity> 
    </application> 

下面的副本樣本屏幕截圖,標籤名稱可以看出,雖然該活動(Activity2)由一個工具欄組成,白色區域是工具欄中的一個編輯文本,工具欄中沒有其他內容。

EDIT 1

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:textColor">@color/white</item> 
     <item name="android:textColorPrimary">@color/white</item> 
     <item name="android:textColorSecondary">@color/white</item> 
    </style> 

編輯2

public class Activity2 extends AppCompatActivity { 


    LinedEditText editText; 
    Toolbar toolbar; 

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


     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     editText = (LinedEditText) findViewById(R.id.editText); 
     setSupportActionBar(toolbar); 


    } 
} 

activity2.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 
    <android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/green" 
     android:id="@+id/toolbar" 
     > 

     <EditText 
      android:layout_width="250dp" 
      android:layout_height="40dp" 
      android:id="@+id/title" 
      android:background="@color/white" 
      android:layout_margin="10dp" 
      /> 
     </android.support.v7.widget.Toolbar> 
    <com.test.testproject.LinedEditText 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:id="@+id/editText" 
     android:gravity="top" 
     /> 
</LinearLayout> 

enter image description here

+0

您可以設置每個活動單獨的labale。

+0

這很好..但我需要知道究竟是什麼問題,爲什麼它會來?這是一個錯誤? –

+0

我認爲默認情況下每個活動都將app_name設置爲標籤。 –

回答

0

UPDATE:

這是你的問題。避免使用工具欄。

<android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/green" 
     android:id="@+id/toolbar" 
     > 

     <EditText 
      android:layout_width="250dp" 
      android:layout_height="40dp" 
      android:id="@+id/title" 
      android:background="@color/white" 
      android:layout_margin="10dp" 
      /> 
     </android.support.v7.widget.Toolbar> 

如果您使用在你的主題NoActionBar。避免在活動的佈局中使用工具欄。這就是您獲取活動名稱的原因。

如果您使用的是工具欄,請確保您禁用了TITLE

+0

從來沒有發生過,所以現在爲什麼是這個問題? –

+0

你使用26個API級別嗎? –

+0

當前的API級別爲23. –

0

檢查了這一點。

getSupportActionBar().setDisplayShowTitleEnabled(false); 
+0

從未發生過現在所以現在爲什麼是這個問題? –

+0

如果你改變你的style.xml像這樣。 false

+0

您必須執行to之一。代碼或XML –

0
Check with setting theme for specific activity..which solves your problem..try this 
<style name = "NoActionBar" parent = "@android:style/Theme.Holo.Light"> 
     <item name = "android:windowActionBar">false</item> 
     <item name = "android:windowNoTitle">true</item> 
    </style> 
+0

解決方案很好..我在尋找爲什麼它現在發生,而不是更早? –

0

只要把onCreate()方法setSupportActionBar(工具欄)之後。

setContentView(R.layout.activity_main); 
    ActionBar actionBar = getActionBar(); 
    actionBar.setTitle(""); 
+0

解決方案很好..我在尋找爲什麼它現在發生,而不是更早?這是一個錯誤嗎? –

+0

你有沒有改變應用程序級別的主題? – Rajan1404930

+0

'AppTheme'是全球主題 –