【发布时间】:2015-07-15 17:45:42
【问题描述】:
我想覆盖系统窗口。
我正在尝试创建类似 AppCompat 样式的按钮。
我试过这个:
XML:
<LinearLayout
...
android:background="?android:attr/windowBackground"
/>
<!--
My layout ...
And button
The buttonBarButtonStyle is in Theme.AppCompat and Theme.AppCompat.Light
-->
<Button
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close" />
服务:
LayoutInflater inflater;
public void setTheme(int theme)
{
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this, theme);
inflater = LayoutInflater.from(this).cloneInContext(contextThemeWrapper);
}
public void onCreate(){
boolean themeDark = getThemeDark();
setTheme(themeDark ? R.style.Theme_AppCompat : R.style.Theme_AppCompat_Light);
super.onCreate();
createView(); // in this method i'm only inflating view using: inflater.inflate(layoutId, null); and adding view to window
}
它在 AppCompat 中工作,但在 AppCompat.Light 中不工作。我有来自 AppCompat 样式(深色)的按钮。截图:
黑暗(作品):
黑暗焦点(作品):
光(作品):
光聚焦(不工作):
在这张图片中,我们可以看到一切正常。但是在手机中它看起来很丑。
我想制作这个按钮(我在同一个应用程序中使用 android.support.v7.app.AlertDialog 创建了具有相同主题的 AlertDialog),看起来还可以:
我不知道为什么它不起作用。 我该怎么做?问题在于焦点时的按钮背景。我不知道为什么背景是深色风格。 我试图设置 AlertDialog.AppCompat.Light 主题但没有工作。
【问题讨论】: