我为我的某个屏幕创建了一个自定义标题栏,并尝试在其他屏幕中使用相同的概念,但是获取android.util.AndroidRuntimeException:您无法将自定义标题与其他标题功能组合在一起。
要求:
styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="titleBarHeading" parent="@android:style/TextAppearance">
<item name="android:textSize">17sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#444444</item>
</style>
<style name="CustomWindowTitleBarBG">
<item name="android:background">#323331</item>
</style>
<style name="TitleBarTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBarBG</item>
</style>
</resources>
manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
andrid:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
>
<activity
android:name="com.example.x.sampleapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.x.sampleapp.ItemActivity"
/>
<activity
android:name="com.example.x.sampleapp.ReminderActivity"
android:theme="@style/TitleBarTheme" > </activity>
</application>
</manifest>
Java类:
public class ReminderActivity extends Activity {
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
context=this;
ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
System.out.println("size is >>>"+list.size());
}
}
即使我添加<item name="android:windowActionBar">false</item>
看到其他帖子
答案 0 :(得分:0)
public class ReminderActivity extends Activity {
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
context=this;
ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
System.out.println("size is >>>"+list.size());
}
}
我的帖子的解决方案
从活动中移除requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
并将label
添加到活动的清单中,如下所示:
<activity
android:name="com.example.sheetal.sampleapp.ItemActivity"
android:label="ss"
android:theme="@style/TitleBarTheme" />