![](/img/trans.png)
[英]How to make clickable and open custom alert dialog in android listview?
[英]How To Make Custom Alert Dialog on Android?
我想用不同的样式制作自定义警报对话框。 众所周知,默认样式是正方形。 我想让它像在糖果迷恋游戏中一样,如果您曾经见过。 我尝试更改背景样式,但是默认背景仍然出现。 这是我的对话框布局的xml文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical"
android:background="@drawable/dialog" >
<ImageView
android:id="@+id/ivPic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
<ScrollView
android:id="@+id/svAlert"
android:layout_width="wrap_content"
android:layout_below="@+id/ivPic"
android:layout_height="200px"
>
<TextView
android:id="@+id/tvMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="text"/>
</ScrollView>
<Button
android:id="@+id/bOKE"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_below="@+id/svAlert"
android:layout_height="wrap_content"
android:text="OK"/>
</RelativeLayout>
请问你能帮帮我吗? 谢谢...
首先,使用背景图片设置自定义主题:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowBackground">@drawable/dialog</item>
</style>
</resources>
然后,将主题设置为您的对话框:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.MyDialogTheme));
您已经为AlertDialog的布局指定了背景。 您应该使默认的windowBackground消失。 因此,将对话框的android:windowBackground
更改为透明:
<style name="YourDialogTheme" parent="android:Theme.Dialog">
...
<item name="android:windowBackground">@android:color/transparent</item>
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.