Android 主题不适用于 Activity

问题描述 投票:0回答:3

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

清单:

    <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> 

自定义_标题_主题.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);

自定义_标题栏.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().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);阻止设置“custom_title_theme”?

这是显示所有内容的屏幕:

enter image description here

android user-interface themes android-manifest
3个回答
1
投票

我建议您尝试以下操作:

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

1
投票

将主题添加到您的 Android Manifeast 文件中。

你缺少@android:style。

使用

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

0
投票

我的项目以模拟器中所需的主题开始。不想从电话开始 你成功解决问题了吗?

© www.soinside.com 2019 - 2024. All rights reserved.