AlertDialog默认按钮除法去除 [英] AlertDialog Default Button Divider Removal

查看:457
本文介绍了AlertDialog默认按钮除法去除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的问题是,每当有一个项数组传递到DialogFragment,存在被取消按钮上面画出一个额外的行(除法也许)

单项AlertDialog

当有数组中的多个项目,出现的对话框正确。

多项目AlertDialog

我怎样才能在单项警告对话框去掉多余的行?

我使用的是DialogFragment与阵列的资源创建一个AlertDialog

  @覆盖
公共对话框onCreateDialog(捆绑savedInstanceState){
    INT itemsId = 0;    捆绑ARGS = getArguments();
    如果(参数!= NULL){
        itemsId = args.getInt(BUNDLE_ITEMS_ARRAY_ID_KEY,itemsId);
    }    如果(itemsId大于0){
        AlertDialog.Builder建设者=新AlertDialog.Builder(getActivity())
                .setItems(itemsId,这一点).setCancelable(真)
                .setNegativeButton(android.R.string.cancel,NULL);
        返回builder.create();
    }
    返回null;
}

我也自定义警告对话框风格

 <样式名称=AppTheme父=@安卓风格/ Theme.Holo.Light.DarkActionBar>
    <项目名称=机器人:dialogTheme> @风格/ MyAlertDialog< /项目>
    <项目名称=机器人:alertDialogTheme> @风格/ MyAlertDialog< /项目>
< /风格>
<样式名称=MyAlertDialog父=@安卓风格/ Theme.Holo.Dialog>
   <项目名称=机器人:windowBackground> @android:彩色/透明< /项目>
< /风格>


解决方案

解决的办法是检查单列表项条件,然后在ListView分的高度设置为0。

  AlertDialog alertDialog = builder.create();
如果(getActivity()。getResources()。getStringArray(itemsId)。长度== 1)
    alertDialog.getListView()setDividerHeight(0)。
返回alertDialog;

The problem is that whenever a single item array is passed into the DialogFragment, there is an extra line (a divider perhaps) that is drawn above the cancel button.

Single Item AlertDialog

When there are multiple items in the array, the dialog appears correctly.

Multi-item AlertDialog

How can I get rid of the extra line in the single item alert dialog?

I'm using a DialogFragment to create an AlertDialog with an array resource

    @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int itemsId = 0;

    Bundle args = getArguments();
    if (args != null) {
        itemsId = args.getInt(BUNDLE_ITEMS_ARRAY_ID_KEY, itemsId);
    }

    if (itemsId > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
                .setItems(itemsId, this).setCancelable(true)
                .setNegativeButton(android.R.string.cancel, null);
        return builder.create();
    } 
    return null;
}

I'm also customizing the alert dialog style

<style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:dialogTheme">@style/MyAlertDialog</item>
    <item name="android:alertDialogTheme">@style/MyAlertDialog</item>
</style>
<style name="MyAlertDialog" parent="@android:style/Theme.Holo.Dialog">
   <item name="android:windowBackground">@android:color/transparent</item>
</style>

解决方案

The solution was to check for the single list item condition and then set the ListView divider's height to 0.

AlertDialog alertDialog = builder.create();
if (getActivity().getResources().getStringArray(itemsId).length == 1)
    alertDialog.getListView().setDividerHeight(0);
return alertDialog;

这篇关于AlertDialog默认按钮除法去除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆