(转)Android:去除自定义dialog的title

原地址:http://blog.csdn.net/u012833380/article/details/49885721


因为我也算是初学吧,遇到很多问题也会懵。总是百度来百度去的,但是这次确实是没找到,虽然是个比较低级的问题,相信找不到的应该不止我一个。所以也算是为了提醒自己,也算是帮助别人。所以就给大家记录了下来。

因为我想要实现一个点击弹出的用户协议dialog。所以还要限制它的高度和宽度。这里我给限制了高度为设备高度的2/3,宽度为设备宽度的3/4。


这是有问题的那个页面。


customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//记住这句话要在setContentView和窗体宽高设置之前执行,否则会报requestFeature() must be called before adding content错误。
    public static MyCustomDialog createDiaLog(Context context) {
        spreferences = context.getSharedPreferences(Config.SHARE_PRE_FILE, 0);
        customDialog = new MyCustomDialog(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_user_deal, null, false);
        customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//这句话,就是决定上面的那个黑框,也就是dialog的title。  
        int width = spreferences.getInt("screenWidth", 480);
        int height = spreferences.getInt("screenHeight", 800);
        Window window = customDialog.getWindow();//这部分是设置dialog宽高的,宽高是我从sharedpreferences里面获取到的。之前程序启动的时候有获取  
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = width / 4 * 3;
        lp.height = height / 3 * 2;
        window.setAttributes(lp);
        customDialog.setContentView(view);
        customDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        return customDialog;
    }


这是解决之后的效果,额,内容只是我复制360的,因为公司那边也没有给内容,所以为了看效果,只能复制一下了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值