设置Window.FEATURE_CUSTOM_TITLE创建AndroidRuntimeException [英] Setting a Window.FEATURE_CUSTOM_TITLE creates AndroidRuntimeException

查看:104
本文介绍了设置Window.FEATURE_CUSTOM_TITLE创建AndroidRuntimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让过去这个错误:

I can't seem to get past this error:

android.util.AndroidRuntimeException:不能将自定义标题   与其他标题功能

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

我正在运行的API> 14

I am running API > 14.

清单如下:

    <activity
        android:name=".activity.ActivityWelcome"
        android:label="@string/app_label_name"
        android:launchMode="singleTask"
        android:clearTaskOnLaunch="true"
        android:theme="@style/My.Theme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

我的行为是做了以下内容:

My activity is doing the following:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.welcome);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title_main);
    ...

其中, R.layout.window_title_main 是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_title"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="5dp" >

    <TextView
        android:id="@+id/textview_title"
        android:drawableLeft="@null"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="-1"/>

</LinearLayout>

这是为什么不是当它似乎为别人打工的工作?

Why is this not working when it seems to work for others?

推荐答案

这是一种错误,将推动你疯狂和超越。

This is the kind of error that will drive you to insanity and beyond.

所以,我碰巧使用 Theme.Holo 因为我父母的主题。 (我自己的主题延伸的主题)

So I happen to be using Theme.Holo as my parent theme. (The theme that my own theme extends)

该文件说:

...操作栏包含在所有使用Theme.Holo活动   主题(或它的子类),这是默认的主题时,   无论是targetSdkVersion或的minSdkVersion属性被设置为11   或更大。

...the action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to "11" or greater.

<一个href="http://developer.android.com/guide/topics/ui/actionbar.html#Adding">http://developer.android.com/guide/topics/ui/actionbar.html#Adding (第一款)

好了,当我尝试去通过上面的方法(我的问题),我得到的错误:

Ok, so when I try to go through the process above (my question) I get the error:

您不能将自定义标题与其他标题功能

You cannot combine custom titles with other title features

嗯,这是因为,在默认情况下的操作栏是设置好的,它不会让你使用一个自定义标题栏为好。

Well, that's because, by default action bar is setup already and it won't allow you to use a custom title bar as well.

文件显示,每一个活动包括操作栏:

Documentation reveals that "each activity includes the action bar":

这样一来,当应用程序在Android 3.0或更高版本,在运行   系统应用全息主题到每个活性,因此,每个   活动包括行动吧。

This way, when the application runs on Android 3.0 or greater, the system applies the holographic theme to each activity, and thus, each activity includes the action bar.

所以,我现在将专注我的时间就改变了操作栏,而不是标题栏!

So, I will now focus my time on altering the action bar and not the title bar!

这篇关于设置Window.FEATURE_CUSTOM_TITLE创建AndroidRuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆