android 设置activity为对话框,且背景为透明

时间:2022-11-16 07:13:50
1.在drawable/目录下建立文件:bg_transparent.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="#88000000" /> <!-- 实体设置为透明 -->

<stroke
android:width="1dp"
color="#FFFFFF" />

<corners android:radius="20dp" />

<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />

</shape>

2.在values/ 目录下,建立风格文件style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme -->
<style name="mytheme" parent="android:style/Theme.Dialog">

<!-- <item name="android:paddingBottom">100px</item> -->
<item name="android:windowBackground">@drawable/upload_dialog</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
</style>
</resources>

3.在Manifest.xml中:
<activity
android:exported="true"
android:label="@string/app_name"
android:name=".ShowChatMessageActivity"
android: