24

我的清单中有一项活动,我曾经使用对话框主题进行样式设置。AppCompat我在库中找不到如何替换它。

  <activity
            android:name=".LoginActivity"
            android:theme="@android:styles/Theme.Holo.Dialog" 
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:label="Login" >

是否有基于材料的等价物?

4

4 回答 4

59

Java 代码

    AlertDialog.Builder builder =
                    new AlertDialog.Builder(SecondActivity.this, R.style.AppCompatAlertDialogStyle);
            builder.setTitle("SCRUM");
            builder.setMessage("In the SCRUM methodology a sprint is the basic unit of development. Each sprint is preceded by a planning meeting, where the tasks for the sprint are identified and an estimated commitment for the sprint goal is made, and followed by a review or retrospective meeting where the progress is reviewed and lessons for the next sprint are identified. During each sprint, the team creates finished portions of a product.....");
            builder.setPositiveButton("OK", null);//second parameter used for onclicklistener
            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>

导入支持 v7 警报对话框

import android.support.v7.app.AlertDialog;

像这样输出,

在此处输入图像描述

于 2015-06-22T08:20:14.427 回答
26

AppCompat 中的对话框还没有基于材质的主题,请参见此处

Will appcompat automatically theme dialogs to look like the Lollipop version?

回复

Not yet, but it's on the todo list.

更新:

在版本22.1中,Support Library您现在可以使用AppCompatDialog获取材质对话框样式

于 2014-10-24T19:15:35.367 回答
9

使用最新的 Appcompat 库

compile 'com.android.support:appcompat-v7:23.2.1'// or any version greater than 22.1

并在清单中使用以下主题

android:theme="@style/Theme.AppCompat.Light.Dialog"
于 2016-04-02T15:13:55.780 回答
0

这应该适合你:https ://github.com/afollestad/material-dialogs

我用它在 a 中构建对话框DialogFragment,并应用了自定义样式。效果很好。

于 2015-02-08T22:25:27.630 回答