2011-12-07 16 views
6

私のアプリケーション用のカスタムタイトルバーを設計しました。それは私にとってもうまくいく。しかし問題がある。カスタムタイトルバーが上書きされる前に、デフォルトのタイトルが表示されます(数秒間)。アンドロイドが提供するデフォルトのタイトルバーを無効にする方法はありますか?androidのカスタムタイトルでデフォルトのタイトルを上書きする方法

私のコードは、/解像度で

window_title.xml /レイアウト解像度で

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myTitle" 
android:text="custom title bar" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:textColor="@color/titletextcolor" 
android:gravity ="center"/> 

color.xml ...のようだったのres /値の

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="customTheme" parent="android:Theme"> 
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground </item> 
    </style> 
</resources> 

のstyles.xml値

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="titlebackgroundcolor">#303010</color> 
    <color name="titletextcolor">#FFFF00</color> 
</resources> 

themes.x解像度でミリリットル../

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="WindowTitleBackground">  
     <item name="android:background">@color/titlebackgroundcolor</item>  
    </style> 
</resources> 

値と私はまた、

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.title" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="7" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:theme="@style/customTheme" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".CustomTitleActivity" 
      android:theme="@style/customTheme" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 
</manifest> 

と私が好きやった私のonCreateメソッドのように、私のmanifest.xmlの活動を更新した

super.onCreate(savedInstanceState); 
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
setContentView(R.layout.main); 
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.window_title); 
final TextView myTitle = (TextView) findViewById(R.id.myTitle); 
myTitle.setText("Converter"); 

そして、これもうまくいく

http://www.edumobile.org/android/android-programming-tutorials/creating-a-custom-title-bar/ でコード化されていて、うまくいきますあまりにも..

最初に来るデフォルトのタイトルを無効にする方法はありますか?あなたはちょうどあなたが好きなあなたのタイトルバーを設計し、あなたの主なレイアウトでトップでそれを設定し、ここではレイアウト

requestWindowFeature(Window.FEATURE_NO_TITLE); 

を設定する前のonCreateに次のコードを使用し、タイトルバーのためにAndroid上で中継する理由

+0

だけでランダムな思考を持って願っています..........テーマを設定し、その他の機能や権限を設定するようなあなたのタイトルバーのための他の任意のものを設定する必要がいけませんあなたはonCreateメソッドの最後の行として "setContentView"を配置しようとしましたか? –

+0

この行を変更しない場合はカスタムタイトルを書く必要があります。android:text = "カスタムタイトルバー"をandroid:text = "" –

+0

@STT LCU&user370305:私はすでに試していました。私はgetWindow()のようにコーディングしていますが、setFeatureInt(Window.FEATURE_CUSTOM_TITLE、R.layout.window_title); setContentView(R.layout.main);エラーが表示されます。しかし、私が質問したようにそれを置くと、それはうまく動作します –

答えて

1

は一例です。..あなたがあなたの活動のレイアウトとしてmain.xmlを設定している場合。のようなあなたのメインレイアウトであなたのタイトルバーを定義することは、あなたのmain.xmlはのonCreate()メソッドのコードを含む、私の活動のJavaファイルで、その後

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 
    //here i have used LinearLayout as example your's can be Relative or whatever 

//here my title bars layout starts containing an icon and a text your's can containing just text or whatever you want 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/my_title_background" 
    android:orientation="horizontal" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginLeft="15dip" 
     android:src="@drawable/my_icon" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginLeft="15dip" 
     android:text="My Application title" 
     android:textColor="#FFFFFF" /> 
</LinearLayout> 

    //and here rest of your layut for your application functionality 
</LinearLayout> 

ようにする必要がありますそのようになります

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.main); 
    //restof code for my class 

あなたは、私はあなたはそれが

+0

私はちょうど私がそれを行う方法を記述することができますか?私はアンドロイドに新しいです。私はタイトルバーを作ったと思う。そのうまくいっている。私のコードをチェックして、私が間違っている場所を示唆しますか? –

+0

あなたの上に上記の行を入れてくださいonCreate(); –

+0

@Aprilとsam.Janz:いいえ...それもうまくいきません...私は自分の作成にそのコードを入れてみました。私がそうするとき、それはエラー –

関連する問題