2016-12-21 11 views
0

私の活動でカスタムタイトルバーを使用しようとしています。され、次の私はカスタムタイトルバーを使用した場合の例外android

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    if (customTitleSupported) { 
     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar); 
    } 
    final TextView txtTitle = (TextView) findViewById(R.id.txtTitle); 
    if (txtTitle != null) { 
     txtTitle.setText("PikMyBox - Welcome to PikMyBox"); 
    } 
    setContentView(R.layout.activity_main); 
} 

custom_title_bar.xmlを使用しているコード

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<TextView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/txtTitle" 
android:layout_alignParentLeft="true"/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/txtCustomText" 
    android:layout_alignParentRight="true"/> 
</RelativeLayout> 

のstyles.xml

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorSplash</item> 
    <item name="android:windowNoTitle">true</item> 
</style> 

たManifest.xml

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    ----- 

私は活動が

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
        at android.app.ActivityThread.access$800(ActivityThread.java:166) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5590) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
        at dalvik.system.NativeStart.main(Native Method) 
       Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features 
        at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:302) 
        at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2975) 
        at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3241) 
        at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1821) 
        at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:363) 
        at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312) 
        at android.support.v7.app.AppCompatDelegateImplV7.findViewById(AppCompatDelegateImplV7.java:229) 
        at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:184) 
        at com.kommlabs.pikmybox.MainActivity.onCreate(MainActivity.java:25) 
        at android.app.Activity.performCreate(Activity.java:5447) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)  
        at android.app.ActivityThread.access$800(ActivityThread.java:166)  
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)  
        at android.os.Handler.dispatchMessage(Handler.java:102)  
        at android.os.Looper.loop(Looper.java:136)  
        at android.app.ActivityThread.main(ActivityThread.java:5590)  
        at java.lang.reflect.Method.invokeNative(Native Method)  
        at java.lang.reflect.Method.invoke(Method.java:515)  
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)  
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)  
        at dalvik.system.NativeStart.main(Native Method)  

どのように私はこの問題を解決することができますが、実行時に、次のエラーを取得mの?

+2

http://stackoverflow.com/questions/27395263/android-util-androidruntimeexception-you-can not-combine-custom-titles-with-othe可能な重複 – Raghunandan

+0

@Raghunandanそれは例外を表示しません。これは、カスタムタイトルバーとデフォルトのタイトルバーの両方を画面に表示します。 –

+0

@Raghunandanまた、最終的なTextView txtTitle =(TextView)findViewById(R.id.txtTitle);をnullにしています。どうして ? –

答えて

0

styles.xmlのandroid:windowNoTitlefalseに変更してください。

0

setContentView(R.layout.activity_main);は、final TextView txtTitle = (TextView) findViewById(R.id.txtTitle);以下です。なぜ例外が発生しているのですか。作成前にビューを初期化しています。ここhttps://stackoverflow.com/a/27410003/3111083を示唆したように、カスタムタイトルバーを使用して、例外の場合にも

setContentView(R.layout.activity_main); 
final TextView txtTitle = (TextView) findViewById(R.id.txtTitle); 

変更それがこのスタイル

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    <item name="android:windowActionBar">false</item> 
    <item name="android:windowNoTitle">false</item> 
</style> 

を使用

関連する問題