2012-01-11 90 views
0

我嘗試在Android上構建應用程序。 而我是Android新手。 但我不知道如何建立這樣的標題欄。 因此,我們可以使用標籤按鈕來提供像Seesmic和Komutta這樣的應用程序名稱。 任何人都可以幫助我給出答案或只是該教程的鏈接?如何創建Android自定義標題欄

謝謝。

https://lh6.ggpht.com/Hf6XKfa9K0B-CvlV6tD6qj2Yt8wJcyJ7wa8vE9BVkBbUDm0Y2pqOxgxVf7auQgXrh0gR

https://lh4.ggpht.com/rwceS5ZK1IZkHHCVixbaXlsHXwstpmIO888aMC4U0uD2oa54NiGvphcp_penGK9Q9WE

我很抱歉,我不能上傳圖片,所以我就可以給的鏈接的形象。

回答

1

這就是所謂的「操作欄」你可以得到它nativly從Android 3.0或搶碼開始做它在早期版本的Android here.

+0

這意味着很多。謝謝 – AdityaSetyadi 2012-01-11 21:40:14

0
  1. 創建一個新的項目,並命名您的主要活動「MyActivity」
  2. 轉到資源 - 繪製並創建一個新的XML文件,並把它稱爲「custom_title_background」,並把下面的代碼:

    <item android:top="20dp"> 
        <shape android:shape="rectangle"> 
         <gradient android:angle="90" android:endcolor="#9eacbf" android:startcolor="#8296af"> 
        </gradient></shape> 
    </item> 
    

這可繪製將用於設置背景從custom_title_bar(來自步驟3),並設定windowTitleBackgroundStyle從custom_title_style(來自步驟4 )

  1. 轉到res-layout並創建一個新的xml並將其命名爲「custom_title_bar」。在這裏,您將創建一個佈局,就像下面代碼的文本視圖:

    <TextView android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:textSize="16sp" 
          android:textColor="@android:color/white" 
          android:textStyle="bold" 
          android:id="@+id/custom_title_text" 
          android:layout_centerInParent="true" 
          android:shadowColor="@android:color/black" 
          android:shadowRadius="3"/> 
    

  2. 轉到資源 - 值,並創建一個新的XML文件,並custom_title_style調用它。在這裏,您將通過覆蓋現有主題來創建新主題。從下面的風格「custom_title_theme」的名稱將被用於清單文件中以「激活」新的主題。

    40dp @繪製/ custom_title_background

  3. 現在去AndroidManifest.xml文件,並把新的主題應用標籤。

  1. 而在這最後一步,你必須去MyActivity類,並把下面的代碼:

    進口android.app.Activity; import android.os.Bundle; import android.view.Window; import android.widget.TextView;

    公共類MyActivity延伸活動{

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
    
        //this must be called BEFORE setContentView 
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    
        setContentView(R.layout.main); 
    
        //this must bew called AFTER setContentView 
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar); 
    
        //set the title 
        TextView textView = (TextView)findViewById(R.id.custom_title_text); 
        textView.setText("Custom Title"); 
    } 
    

    }