Android 自定义倾斜不与标题特征组合
我已经创建了自定义标题栏。现在我想添加选项卡。。我已经实现了以下代码。但它显示了上述错误 这是我的主要活动课Android 自定义倾斜不与标题特征组合,android,android-logcat,titlebar,custom-titlebar,Android,Android Logcat,Titlebar,Custom Titlebar,我已经创建了自定义标题栏。现在我想添加选项卡。。我已经实现了以下代码。但它显示了上述错误 这是我的主要活动课 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.activity_main_list)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main_list);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.maintitlebar);
loadPage();
}
这是主活动的布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context=".MainListActivity"
android:padding="0dp"
android:id="@+id/child_r1"
>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:layout_alignParentTop="true"
android:transitionGroup="false"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>
这是清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.talha.appforblog" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyMaterialTheme" > >
<activity
android:name=".MainListActivity"
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=".ContentGetter"
android:label="@string/title_activity_content_getter" >
</activity>
<activity
android:name=".ColoumnView"
android:label="@string/title_activity_coloumn_view" >
</activity>
</application>
>
您正在使用的theme.AppCompat.Light主题包含以下定义(在其父级中):
true
因此,主题说它没有标题,而您正在使用自定义标题。这是不相容的
您正在使用的主题包含一个操作栏,操作栏中的标题处理方式不同
试试这个:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">false</item>
</style>
假的
假的
我必须在style.xml中对此进行更改。对吗?我必须在Custom_Theme.xml的TitleBarTheme中也将其更改为true吗??如果你在哪里使用MyMaterialTheme,那将非常有帮助。我正在学习教程。他一直执行到这里,并说检查通知栏是否发生了变化,然后你们就朝着正确的方向前进了。我正在检查这一点,你在清单中使用了MyMaterialTheme
,是吗?是的。我也编辑了上面的清单文件,你能找出错误吗?
2732-2732/com.example.talha.appforblog E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.talha.appforblog, PID: 2732
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.talha.appforblog/com.example.talha.appforblog.MainListActivity}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:309)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3244)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3561)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:367)
at android.app.Activity.setContentView(Activity.java:2144)
at com.example.talha.appforblog.MainListActivity.onCreate(MainListActivity.java:82)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:225 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.talha.appforblog" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyMaterialTheme" > >
<activity
android:name=".MainListActivity"
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=".ContentGetter"
android:label="@string/title_activity_content_getter" >
</activity>
<activity
android:name=".ColoumnView"
android:label="@string/title_activity_coloumn_view" >
</activity>
</application>
<item name="android:windowNoTitle">true</item>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">false</item>
</style>