Android主题不适用于Activity

rqmkfv5c  于 5个月前  发布在  Android
关注(0)|答案(2)|浏览(61)

当我在布局中设置背景颜色时,一切都很完美。然而,**当我试图从主题设置它时,它不起作用。**似乎我做错了什么。下面是代码。

清单:

<activity android:name="com.example.somma.MainActivity"
    android:label="@string/app_name"
    android:theme="@style/custom_title_theme"
    >
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

字符串

custom_title_theme.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="custom_title_theme" parent="android:Theme">
    <item name="android:windowTitleSize">40dp</item>
    <item name="android:windowTitleBackgroundStyle">@drawable/custom_title_background</item>
    <item name="android:background">@color/Meerenguee</item>
</style>    
</resources>


这是因为在每一个类中,我都调用这些行onStart()吗?

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
      setContentView(com.example.somma.R.layout.sumwindow);
      getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);

custom_title_bar.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="@drawable/custom_title_background">

<TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="16sp"
          android:textColor="@color/cream_brown"
          android:textStyle="bold"
          android:id="@+id/custom_title_text"
          android:text="@string/app_name"
          android:layout_centerInParent="true"
          android:shadowColor="@android:color/black"
          android:shadowRadius="3"/>

<Button android:id="@+id/settings_button" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentRight="true"
android:text="@string/settings"
android:onClick="openSharedPref"
android:background="@drawable/header_button"/>

</RelativeLayout>


getWindow(). setObjectureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title_bar);是否阻止设置“custom_title_theme”?
这里是一个屏幕上的一切是如何出现的:
x1c 0d1x的数据

cwtwac6a

cwtwac6a1#

我建议你尝试以下操作:

<application 
   android:icon="@drawable/icon" 
   android:label="@string/app_name" 
   android:theme="@style/custom_title_theme"/>

字符串

gmxoilav

gmxoilav2#

添加主题到你的android manifest文件。
您缺少@android:style。
使用

android:theme="@android:style/custom_title_theme" instead of 
android:theme="@style/custom_title_theme"

字符串

相关问题