Android主题不适用于活动

皮诺洛

当我在布局中设置背景色时,一切都将正常运行。但是,当我尝试从主题设置它时,它将不起作用。看来我做错了。这是代码。

显现:

    <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()。setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title_bar); 阻止设置“ custom_title_theme”?

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

在此处输入图片说明

里特什·古尼(Ritesh Gune)

我建议您尝试以下操作:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章