0

我有以下代码导致错误消息,我*无法将 FEATURE_CUSTOM_TITLE 与其他标题功能结合*(据我所知...)

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

String customTitleStr = getIntent().getExtras().getString("Title");

Boolean customTitleSupported = this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

if ( (customTitleSupported) && (customTitleStr != null) ) {
  getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.override_titlebar);
  final TextView myTitleText = (TextView) findViewById(R.id.myTitleText);
  if ( myTitleText != null ) {
      myTitleText.setText(customTitleStr);
  }                  
}

我试过地方setContentView(R.layout.); this.requestWindowFeature之前和之后都没有变化。

我的清单针对的是:

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

供参考(不知道是否相关),我也无法主题化我的标题栏。(直接忽略。)

以防万一,我的主题的一些代码片段:

AndroidManifest.xml:

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

样式.xml:

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

   <style name="AppTheme" parent="AppBaseTheme">
   </style>

   // ...

   <style name="MicTheme" parent="AppTheme">
     <item name="android:windowTitleSize">44dip</item>
     <item name="android:windowTitleBackgroundStyle">@style/MicWindowTitleBackground</item>
     <item name="android:windowTitleStyle">@style/MicWindowTitle</item>     
   </style>
4

1 回答 1

0

请尝试使用此代码。

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class CustomTitleBar extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            setContentView(R.layout.main);
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);

    }
}

有关如何设置自定义标题栏的更多信息,请遵循以下教程。

http://www.edumobile.org/android/android-programming-tutorials/creating-a-custom-title-bar/

http://www.powenko.com/en/?p=214

http://7thursdays.wordpress.com/2012/10/14/how-to-make-a-custom-title-with-android/ 希望这对您有所帮助。

编辑 这里是工作截图。

在此处输入图像描述

于 2013-06-10T11:31:03.650 回答