在AlertDialog中添加边框 [英] Adding a border to an AlertDialog
问题描述
我正在尝试在警报对话框中添加边框.我希望使它看起来像这样:
I am trying to add a border to an alert dialog. I am hoping to make it look like this:
到目前为止,我发现的最佳解决方案是使用可绘制的九个补丁作为对话框的背景.
The best solution I have found thus far is to use a nine patch drawable as the background for the dialog.
问题是我还没有找到一种方法来制作九个补丁背景,实际上却为对话框周围提供了一条一致的白线.到目前为止,这是我最好的尝试(对不起,有点难以理解...):
The problem with this is that I have not found a way to make a nine patch background that actually gives the dialog a consistent white line around it. This has been my best attempt thus far (sorry it is a little hard to see...) :
问题在于,这会产生如下所示的对话框:
The problem is that this produces a dialog like this:
这里的问题是双重的.两侧的线太粗了,顶部的线被阴影淡化了.
The problems here are twofold; the lines at the sides are way too thick, and the lines at the top are kind of faded by the shadow.
我唯一的想法是找到一个可以正常显示边框的九个补丁,或者找到一种方法来获取警报对话框的主布局",以便直接在其中添加填充.
My only ideas are to either find a working nine patch that gives a consistently thick border, or to find a way to get the 'main layout' of the alert dialog, so I can add a padding to that directly.
在这样的警报"对话框上设置边框的最佳方法是什么?
What is the best way to go about setting up a border on an Alert Dialog like this?
推荐答案
发问者的答案非常接近我想要的答案,但是它仍然在对话框中留下了我不感兴趣的大黑线.
The answer by questioner was very close to what I wanted, but it still left a big black line around the dialog that I was not interested in.
我从图层列表中删除了一个图层,并自定义了白色边框上的填充.我也没有不将背景设置为透明,因为建议在注释中是个好主意.
I deleted one of the layers from the layer list, and customised the padding on the white border. I also did not set the background to transparent as suggested would be a good idea in the comments.
该项目内部的形状是在对话框上为背景提供相同的弯曲边缘(如果在3.0+上看起来非常接近,则可以看到一些圆角像素).
The shape the is inside the item is to give the background the same curved edges on a dialog (if you look really closely on 3.0+, you can see a few pixels of round corners).
在drawable
文件夹中的dialog_border.xml
文件中,我有以下内容:
In a dialog_border.xml
file in the drawable
folder, I had this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="6dp"
android:left="13dp"
android:right="13dp"
android:bottom="6dp">
<shape android:shape="rectangle" >
<solid android:color="@color/offWhite" />
<corners
android:radius="3dp"/>
</shape>
</item>
</layer-list>
在我的风格中,我有这个:
And in my style I had this:
<style name="DialogTheme" parent="android:Theme.Holo.Dialog">
<item name="android:windowBackground">@drawable/dialog_border</item>
</style>
尽管可能可以通过编程而不是样式设置(如有必要).
Although it could probably be set programatically rather than in the style if necessary.
这篇关于在AlertDialog中添加边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!