我在我的Manifest中有一个活动,我曾经用Dialog主题设计风格。我找不到如何在AppCompat
库中替换它。
<activity
android:name=".LoginActivity"
android:theme="@android:styles/Theme.Holo.Dialog"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="Login" >
是否存在基于材料的等效物?
答案 0 :(得分:58)
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;
像这样的输出,
答案 1 :(得分:24)
AppCompat中的对话框尚无基于材料的主题,请参阅here
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
答案 2 :(得分:9)
使用最新的Appcompat库
compile 'com.android.support:appcompat-v7:23.2.1'// or any version greater than 22.1
并在Manifest中使用以下主题
android:theme="@style/Theme.AppCompat.Light.Dialog"
答案 3 :(得分:0)
这应该适合您:https://github.com/afollestad/material-dialogs
我使用它在DialogFragment
中构建对话框,并应用了自定义样式。效果很好。