2
我想有一个黑暗的活性对话的主题,所以我定义如下:黑暗活动对话的主题不工作
<style name="AppThemeDialogActivityDark" parent="Theme.AppCompat.Dialog">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- dark toolbar + dark popup menu -->
<item name="toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<!-- trying to forcefully set the background and text color -->
<item name="android:windowBackground">@android:color/background_dark</item>
<item name="android:textColor">@color/white</item>
<item name="android:minWidth">320dp</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
活动:
public class FeedbackActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
// darkTheme returns true!!!
setTheme(MainApp.getPrefs().darkTheme() ? R.style.AppThemeDialogActivityDark : R.style.AppThemeDialogActivity);
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_feedback);
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:theme="?toolbarTheme"/>
<ListView
android:padding="12dp"
android:id="@+id/lvFeedback"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ScrollView
android:id="@+id/svFeedback"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="0dp">
<TextView
android:padding="12dp"
android:id="@+id/tvFeedback"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
<Button
android:padding="12dp"
android:id="@+id/btButton"
style="?borderlessButtonStyle"
android:elevation="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</layout>
什么我在这里想念吗?为什么我的活动对话框有白色背景而不是黑色背景?
编辑 - 有趣的细节
- 设置视图的背景的,以
android:background="?android:windowBackground"
确实工作。但我必须为ListView和TextView执行此操作。这个主题属性的工作意味着,主题是正确应用,似乎默认背景是在对话框主题中的另一个主题属性中定义的? - 我的
ListView
项目是正确的主题,只需使用android.R.layout.simple_list_item_1
作为布局,我不需要设置它们的背景/文本颜色,它们正确为黑暗主题主题,但不可见,如果我没有设置ListView
背景手动像上面
您应该检查你的价值 - VXX文件夹,看到他们的样式文件。也许对他们中的一些人来说,风格与你需要的风格不同。你也应该检查你的布局文件,看看他们是否使用你的样式文件中的任何指定的样式。 – Merka
这是一个好主意,但我很懒惰为不同的屏幕尺寸创建特殊的样式,现在检查了这一点,但事实并非如此 – prom85
我添加了我的xml布局,我没有在那里手动设置任何背景颜色。 。我没有在代码中设置任何颜色,这个活动只是一个非常简单的活动,只有几行代码 – prom85