Android 功能\自定义\标题/不能将自定义标题与其他标题功能组合

Android 功能\自定义\标题/不能将自定义标题与其他标题功能组合,android,Android,我有一个似乎无法解决的问题 protected void onCreate(Bundle savedInstanceState) { // comments describe what happens super.onCreate(savedInstanceState); Boolean customTitleSupported = this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // crash at undern

我有一个似乎无法解决的问题

protected void onCreate(Bundle savedInstanceState) {
  // comments describe what happens
  super.onCreate(savedInstanceState);
  Boolean customTitleSupported = this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
  // crash at underneath line
  try
  {
    setContentView(R.layout.myactivity); 
  }
  catch (Exception e)
  {
   // You cannot combine custom titles with other title features
  }
  // never gets to underneath line
  if customTitleSupported {
    this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.override_titlebar);
  }
}

我使用android-support-v4.jar库

requestWindowFeature(窗口功能\u无\u标题)不会导致任何问题

从AndroidManifest.xml文件

<uses-sdk
  android:minSdkVersion="8"
  android:targetSdkVersion="17"   
/>

<application
  android:allowBackup="true"
  android:icon="@drawable/replace__logo__app_256_256"
  android:label="@string/MicAppName"
  android:theme="@style/MicTheme"
  android:name="com.example.app.MicApp"
>

styles.xml

<style name="AppBaseTheme" parent="android:Theme">
    <item name="android:windowNoTitle">false</item>
</style>
   <style name="MicWindowTitleBackground">
        <item name="android:background">@android:color/white</item>
        <item name="android:padding">0px</item>
    </style>    
   <style name="MicWindowTitleTextAppearance">
       <item name="android:textSize">20sp</item>
       <item name="android:textStyle">bold|italic</item>        
   </style>           
   <style name="MicWindowTitle">
     <item name="android:textAppearance">@style/MicWindowTitleTextAppearance</item>
     <item name="android:shadowDx">0</item>
     <item name="android:shadowDy">0</item>
     <item name="android:shadowRadius">5</item>
     <item name="android:shadowColor">#1155CC</item>
   </style>
   <style name="MicTheme" parent="AppBaseTheme">             
     <item name="android:windowTitleSize">44dip</item>
     <item name="android:windowTitleBackgroundStyle">@style/MicWindowTitleBackground</item>
     <item name="android:windowTitleStyle">@style/MicWindowTitle</item>          
   </style>    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent" 
  android:layout_height="match_parent"
  android:orientation="horizontal"
>                
<ImageView android:id="@+id/myTitleLogo" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:background="@drawable/replace__logo__app_256_256">
>
</ImageView>    
<TextView     
  android:id="@+id/myTitleText" 
  android:text="@string/dotdotdot" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent"        
/>
</LinearLayout>

错误的
我的主题\u support.xml

<style name="AppBaseTheme" parent="android:Theme">
    <item name="android:windowNoTitle">false</item>
</style>
   <style name="MicWindowTitleBackground">
        <item name="android:background">@android:color/white</item>
        <item name="android:padding">0px</item>
    </style>    
   <style name="MicWindowTitleTextAppearance">
       <item name="android:textSize">20sp</item>
       <item name="android:textStyle">bold|italic</item>        
   </style>           
   <style name="MicWindowTitle">
     <item name="android:textAppearance">@style/MicWindowTitleTextAppearance</item>
     <item name="android:shadowDx">0</item>
     <item name="android:shadowDy">0</item>
     <item name="android:shadowRadius">5</item>
     <item name="android:shadowColor">#1155CC</item>
   </style>
   <style name="MicTheme" parent="AppBaseTheme">             
     <item name="android:windowTitleSize">44dip</item>
     <item name="android:windowTitleBackgroundStyle">@style/MicWindowTitleBackground</item>
     <item name="android:windowTitleStyle">@style/MicWindowTitle</item>          
   </style>    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent" 
  android:layout_height="match_parent"
  android:orientation="horizontal"
>                
<ImageView android:id="@+id/myTitleLogo" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:background="@drawable/replace__logo__app_256_256">
>
</ImageView>    
<TextView     
  android:id="@+id/myTitleText" 
  android:text="@string/dotdotdot" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent"        
/>
</LinearLayout>

@android:彩色/白色
0px
20便士
粗体|斜体
@style/MicWindowTitleText外观
0
0
5.
#1155CC
来自my_theme.xml

<style name="AppBaseTheme" parent="android:Theme">
    <item name="android:windowNoTitle">false</item>
</style>
   <style name="MicWindowTitleBackground">
        <item name="android:background">@android:color/white</item>
        <item name="android:padding">0px</item>
    </style>    
   <style name="MicWindowTitleTextAppearance">
       <item name="android:textSize">20sp</item>
       <item name="android:textStyle">bold|italic</item>        
   </style>           
   <style name="MicWindowTitle">
     <item name="android:textAppearance">@style/MicWindowTitleTextAppearance</item>
     <item name="android:shadowDx">0</item>
     <item name="android:shadowDy">0</item>
     <item name="android:shadowRadius">5</item>
     <item name="android:shadowColor">#1155CC</item>
   </style>
   <style name="MicTheme" parent="AppBaseTheme">             
     <item name="android:windowTitleSize">44dip</item>
     <item name="android:windowTitleBackgroundStyle">@style/MicWindowTitleBackground</item>
     <item name="android:windowTitleStyle">@style/MicWindowTitle</item>          
   </style>    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent" 
  android:layout_height="match_parent"
  android:orientation="horizontal"
>                
<ImageView android:id="@+id/myTitleLogo" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:background="@drawable/replace__logo__app_256_256">
>
</ImageView>    
<TextView     
  android:id="@+id/myTitleText" 
  android:text="@string/dotdotdot" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent"        
/>
</LinearLayout>

44度
@样式/标题背景
@样式/标题

最后,覆盖_titlebar.xml

<style name="AppBaseTheme" parent="android:Theme">
    <item name="android:windowNoTitle">false</item>
</style>
   <style name="MicWindowTitleBackground">
        <item name="android:background">@android:color/white</item>
        <item name="android:padding">0px</item>
    </style>    
   <style name="MicWindowTitleTextAppearance">
       <item name="android:textSize">20sp</item>
       <item name="android:textStyle">bold|italic</item>        
   </style>           
   <style name="MicWindowTitle">
     <item name="android:textAppearance">@style/MicWindowTitleTextAppearance</item>
     <item name="android:shadowDx">0</item>
     <item name="android:shadowDy">0</item>
     <item name="android:shadowRadius">5</item>
     <item name="android:shadowColor">#1155CC</item>
   </style>
   <style name="MicTheme" parent="AppBaseTheme">             
     <item name="android:windowTitleSize">44dip</item>
     <item name="android:windowTitleBackgroundStyle">@style/MicWindowTitleBackground</item>
     <item name="android:windowTitleStyle">@style/MicWindowTitle</item>          
   </style>    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent" 
  android:layout_height="match_parent"
  android:orientation="horizontal"
>                
<ImageView android:id="@+id/myTitleLogo" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:background="@drawable/replace__logo__app_256_256">
>
</ImageView>    
<TextView     
  android:id="@+id/myTitleText" 
  android:text="@string/dotdotdot" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent"        
/>
</LinearLayout>

>

我错过了我有一个单独的style.xml用于从不使用Android的手机

<style name="AppBaseTheme" parent="android:Theme.Holo.Light">

换成

<style name="AppBaseTheme" parent="android:Theme.Light">


我想
this.getWindow().setFeatureInt(…
必须在setContentView之前运行