AlertDialog
创建一个只有进度条的对话框
xxx.java
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setView(R.layout.window_loading)
.setCancelable(false); // 对话框外点击无法退出
dialog = builder.create();
Window window = dialog.getWindow();
if (window != null) {
// 设置背景透明
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
dialog.show();
layout/window_loading.xml
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="true" />
修改按钮的文字颜色
values/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- ... -->
<item name="buttonBarPositiveButtonStyle">@style/positiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">@style/negativeButtonStyle</item>
</style>
<style name="positiveButtonStyle" parent="Base.Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">@color/zkhRed</item>
</style>
<style name="negativeButtonStyle" parent="Base.Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">@color/textNormal</item>
</style>
参考:Android-用style修改AlertDialog修改按钮文字颜色
显示富文本
values/strings.xml
<string name="test_string"><![CDATA[中间是<font color=\'#ff0000\'>红字</font>哈]]></string>
xx.java
new AlertDialog.Builder()
.setMessage(Html.fromHtml(getString(R.string.test_string)))
...
文档信息
- 本文作者:王玉镇wangyuzhen
- 本文链接:https://wangyuzhen666.github.io//wiki/android-view-dialog/
- 版权声明:Creative Commons 4.0 传播此文章时,您需要遵守知识共享协议。 署名(BY)&非商业性(NC)&相同方式共享(SA)------------------------------- When disseminating this article, you need to adhere to a Creative Commons license. Attribution (BY) & Non-Commercial (NC) & Shareby Manner (SA) .(Creative Commons 4.0)