[Android记录]自定义对话框--模拟Dim

背景

Adnroid在弹出Dialog的时候,默认在dialog背后会产生办透明的模糊效果(backgroundDim).这个dim层可以调整模糊值:

<item name="android:backgroundDimEnabled">true</item><!-- 开启背景模糊 -->
<item name="android:backgroundDimAmount">0.5</item><!-- 背景模糊值 -->
现在的问题是要改变此dim层的颜色,我没有找到修改这个dim color 的方法,因此只能弄点偏门了.

解决办法:

将对话框覆盖整个activity,然后自定义背景.

class MockDimDialog extends Dialog{
	
	public MockDimDialog(Context context) {
		super(context, R.style.MockDimDialog);
		setContentView(R.layout.sample_segment_dialog);
		WindowManager.LayoutParams wlp = getWindow().getAttributes();
		wlp.width = WindowManager.LayoutParams.MATCH_PARENT;
		wlp.height = WindowManager.LayoutParams.MATCH_PARENT;
		//下面两行用来保留status bar,不然就全屏了
		wlp.gravity = Gravity.TOP;
		wlp.y = 1;
		getWindow().setAttributes(wlp);
	}
}
样式:

<style name="MockDimDialog" parent="android:Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:windowBackground">@color/dim</item>
    </style>
    <color name="dim">#55ff6600</color>

自定义的dialog view:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <ProgressBar
        style="@android:style/Widget.ProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dip"
        android:textSize="20dip"
        android:textColor="#707070"
        android:text="Loading..." />

</LinearLayout>
显示效果:



转载于:https://my.oschina.net/xesam/blog/148303

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值