在自定义对话框的Android图标 [英] Icons in custom dialogs android
本文介绍了在自定义对话框的Android图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法来设置的自定义对话框的图标不使用AlertDialog方法? 对话框中有标题,但缺少好的分频器和设置图标的功能,但肯定必须有,而不必使用AlertDialog得到两者的方法是什么?
Is there a way to set an icon on a custom dialog without using the AlertDialog methods? Dialog has title, but is missing that nice divider and the ability to set an icon, but surely there must be a way of getting both without having to use AlertDialog?
推荐答案
您可以添加一个图标具有以下code:
You can add an icon with the following code:
Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Dialog Title");
dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.your_icon);
有关除法,你可以简单地添加一个的ImageView
到您的对话框布局:
For a divider you can simply add an ImageView
to your dialog layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:src="@android:drawable/divider_horizontal_dim_dark"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="content"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
这篇关于在自定义对话框的Android图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文