Cot*_*nyo 8 transparency android android-layout android-alertdialog
我有一个自定义AlertDialog,我想让它的背景完全透明.通常,要使活动完全透明,我会执行以下操作
#00000000在xml布局中设置背景
在活动的清单集中android:theme="@android:style/Theme.Holo.Dialog".
在onCreate中添加getWindow().setBackgroundDrawable(new ColorDrawable(0)).
但是现在我正在处理一个Dialog,我该如何实现透明度呢?
这是对话框代码:
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.activity_mine1,
(ViewGroup) findViewById(R.layout.mine1));
mine1 = new AlertDialog.Builder(this);
mine1.setView(dialoglayout);
mine1.show();
Run Code Online (Sandbox Code Playgroud)
我的xml只是一个带有其他子视图的relativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000" >
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
注意:我已经在这里看了一些类似的帖子,但它们似乎没有用.
我的真正原因是我真正想要使用的背景不是矩形.我让它在一项活动中工作.但我想改用对话框.
编辑:
进一步玩,我有这个 style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomDialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
我添加为
new AlertDialog.Builder(this, R.style.CustomDialog)
Run Code Online (Sandbox Code Playgroud)
<style name="CustomAlertDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:width">300dip</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Dialog connectionDialog = new Dialog(this, R.style.CustomAlertDialog);
connectionDialog.setContentView(set your view here);
connectionDialog.show();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11990 次 |
| 最近记录: |