2014-03-30 125 views
0

我在Eclipse Android應用程序中有5個佈局視圖。我想在所有圖形佈局中顯示不同的佈局標題和標題圖標圖像(位於左上角),而不是以編程方式顯示。Android:如何設置不同的佈局標題和標題欄圖標圖像

目前,它在所有佈局中顯示相同的應用標題,並在所有視圖中顯示應用圖標圖像。

<application android:name="singleton" 
    android:allowBackup="true" 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 

我試過登錄活動標題標籤如下,login_name已經添加到字符串中:但是,這裏沒有顯示任何標題。

<activity 
     android:name="com.example.myappandroid.LoginActivity" 
     android:label="@string/login_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

請指教,如何解決這個問題通過圖形化佈局?

+0

什麼樣的佈局?活動?請注意,「操作欄」(標題和圖標的顯示位置)屬於一個活動。因此,通過XML,您只能在/上指定文本。如果您需要在活動中間更改標題/圖標,則必須以編程方式進行。但它非常簡單,只需getActionBar()。setTitle(「hi」)將在活動級別執行此操作,或者在任何視圖級別執行((Activity)getContext())。getActionBar()。setTitle()。或者你可以定義不同的活動,每個不同的佈局,圖標和標題 – rupps

+0

謝謝!我試過this.setTitle(「Login」);這是工作。 – Stella

+0

非常好! :)請注意,如果你做this.getActionBar()。 ...您可以在動作欄中更改更多內容:圖標,顏色等... – rupps

回答

0

你是否說你想在操作欄上自定義圖標和標題?如果是,那麼我會提及我爲此所做的... 1.首先我創建一個自定義xml文件 2.ActionBar actionBar = getActionBar(); actionBar.setCustomView(R.layout.action_bar); //使用它來加載你自己的操作條 actionBar.setDisplayShowCustomEnabled(true);

0

清楚我在我的項目最近確實是..

<?xml version="1.0" encoding="utf-8"?>//first i created a xml file for the ui i need 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TopBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#E6E7E9" > 

    <ImageButton 
     android:id="@+id/baricon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="@null" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

ActionBar actionBar=getActionBar();// then i call this part in my activity 
actionBar.setCustomView(R.layout.action_bar); 
actionBar.setDisplayShowCustomEnabled(true); 
enter code here