2015-02-08 43 views
1

TabHost我們可以做getActionBar().setTitle("ACTITIVTY TITLE")如何在Intent中設置活動標題?

但是如何在intent

有沒有可能的方法來設置標題intent

代碼

Intent i = new Intent(MenuActivity.this, DrawerListActivity.class); 
       startActivity(i); 
       Toast.makeText(getBaseContext(), "RF number: " + 
         KEY_RFnumber, Toast.LENGTH_SHORT).show(); 
+1

設置標題字符串作爲一個額外的,然後用額外的下一個活動啓動? – stkent 2015-02-08 03:55:40

回答

1

不能與意圖直接設置標題。您可以在意圖中傳遞標題,並讓目標活動從意圖中提取標題並設置它。這隻會是目標活動中的幾行額外代碼。

+0

是的。謝謝先生。它完美的作品。 – 2015-02-08 05:16:41

+0

如果這個答案對你有幫助,確保你接受它 – thepoosh 2015-02-08 06:34:41

6

MainActivity.class

public void send(View view) { 
    Intent intent = new Intent(this, DrawerListActivity.class); 
    String message = "Drawer Title"; 
    intent.putExtra("key", message); 
    startActivity(intent); 
} 

DrawerListActivity.class,在onCreate()

String message = getIntent().getStringExtra("key").toString(); // Now, message has Drawer title 
setTitle(message); 

現在,設置該消息標題。

0

我明白了!我只是從我的MainActivity聲明瞭一個公共靜態String,它包含一個我在Intent中設置的字符串,然後調用我的DrawerListActivity。它完美的工作!謝謝。

0

我只是貼上對於這個問題可能是它會幫你另外一個人回答

<application 
       android:allowBackup="true" 
       android:icon="@drawable/ic_launcher" 
       android:label="@string/app_name" 
       android:theme="@style/AppTheme" > 
       <activity 
        android:name=".MainActivity" 
        android:label="@string/app_name_full" > 
     //This is my custom title name on activity. <- The question is about this one. 
        <intent-filter android:label="@string/app_launcher_name" > //This is my custom Icon title name (launcher name that you see in android apps/homescreen) 
         <action android:name="android.intent.action.MAIN" /> 

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