我只是按照这个http://www.laurivan.com/make-dialogs-obey-your-material-theme/在材料设计风格中设计我的提醒对话框。然而,我发现我仍然不能像这个网站一样设计风格,下面是我的代码和截图:
值-v14/styles.xml:
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/colorPrimary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:dialogTheme">@style/MyDialogTheme</item>
<item name="android:alertDialogTheme">@style/MyDialogTheme</item>
</style>
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
values/color.xml
<resources>
<color name="colorPrimaryDark">#3367d6</color>
<color name="colorPrimary">#4285f4</color>
<color name="windowBackgroundColor">#eeeeee</color>
<color name = "transparent">#0000</color>
</resources>截图:

我想要删除分隔符和btn是在填充正确的风格,谢谢!
发布于 2015-04-23 15:45:30
通过新的AppCompat v22.1,您可以使用新的android.support.v7.app.AlertDialog。
只需使用如下代码:
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("Dialog");
builder.setMessage("Lorem ipsum dolor ....");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();并使用这样的样式:
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFCC00</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#5fa3d0</item>
</style>您可以对所有设备使用单个样式文件。
发布于 2015-07-27 12:03:07
我找到的设置对话框样式的最佳解决方案是像你一样在你的styles.xml中包含属性,也设置一个透明的颜色(在colors.xml中),确保包括完整的#AARRGGBB:
<color name="transparent">#00000000</color>然后还要确保将主题添加到您的对话框布局中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">
<TextView
android:id="@+id/dialog_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:text="Dialog Text"/>
</LinearLayout>注意:您应该将"Theme.AppCompat.Light.Dialog“的父级设置为"MyDialogTheme”的父级(在示例中)。
遵循这里的开发人员指南中的“将事件传递回对话框宿主”一节:Link
确保重写对话框片段的类中的onAttach()和onCreateDialog()。
注意,你不必让你的主activity扩展FragmentActivity,你可以扩展AppCompatActivity,并且仍然在activity类中包含库(用于11+接口):
用android.app.DialogFragment代替android.support.v4.app.DialogFragment
尽管您的屏幕截图显示了一个日期选择器对话框,但上面的方法适用于简单的(和最常用的)警报和/或对话框。在上面的文档链接中,它们提供了特定于日期和时间选择器的更多信息。
https://stackoverflow.com/questions/29813250
复制相似问题