自定义的高度和宽度自充气alertdialog布局的android [英] custom height and width in custom inflate alertdialog layout android

查看:660
本文介绍了自定义的高度和宽度自充气alertdialog布局的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在alertdialog膨胀自定义布局。我得到它,但宽度扩大到FILL_PARENT。我曾尝试在XML文件中把WRAP_CONTENT或自定义大小(例如200dp),它是有史以来FILL_PARENT。

我想把我自己的高度和宽度,如(200dp,150dp),我怎么可以把这个?

我已阅读并在这个网站尝试一些解决方案,但我不能解决我的问题,谁能帮助我?在此先感谢了。

我在这里给我的Java code

 `方式>查看FF = getLayoutInflater()膨胀(R.layout.customlayout,NULL);
        >>按钮菜单=(按钮)ff.findViewById(R.id.menu);
        >>
menu.setOnClickListener(新View.OnClickListener(){
            >>
公共无效的onClick(视图v){> // TODO自动生成方法存根>> gotomenu();
            }
            });
        >
AlertDialog对话框=新AlertDialog.Builder(本)
> .setView(FF)> 。创建();> dialog.show();`


解决方案

如果你想高度和宽度上你自己的方式不是让自定义类像下面延长

对话框

 公共类AlertCustomDialog扩展对话框{公共AlertCustomDialog(最终上下文的背景下,事件e){
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          的setContentView(/ *布局* /);
          setCancelable(真);
 }}

和电话

 新AlertCustomDialog(背景下,E).show();

当你需要

否则你可以定义的活动,并把code清单中象下面这样:

 <活动机器人:名字=/ *你的活动名称* /
   机器人:主题=@安卓风格/ Theme.Dialog
        机器人:configChanges =方向| keyboardHidden/>

i'm trying to inflate a custom layout in an alertdialog. I get it, but width is expanded to fill_parent. I have tried in xml file to put wrap_content or custom size (example 200dp) and it's ever fill_parent.

I want to put my own height and width, like (200dp, 150dp), how can i put this?

I have read and tried some solutions in this web, but i can't solve my problem, can anyone help me? thanks in advance for it.

I give my java code here

`>View ff = getLayoutInflater().inflate(R.layout.customlayout, null);
        >>Button menu = (Button)ff.findViewById(R.id.menu);
        >>
menu.setOnClickListener(new View.OnClickListener() {                                    
            >>
public void onClick(View v) {

>// TODO Auto-generated method stub 

>>gotomenu();
            }
            }); 
        >
AlertDialog dialog = new AlertDialog.Builder(this)


>.setView(ff)

> .create();        

> dialog.show();`

解决方案

if you want to make height and width on your own way than make custom class extend dialog like below

public class AlertCustomDialog extends Dialog {

public AlertCustomDialog(final Context context,  Event e) {
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(/*your layout*/);
          setCancelable(true);
 }

}

and call

    new  AlertCustomDialog(context, e).show();

when you need

otherwise you can define Activity and put code in manifest like below:

  <activity android:name="/*your activity name*/"
   android:theme="@android:style/Theme.Dialog"
        android:configChanges="orientation|keyboardHidden" />

这篇关于自定义的高度和宽度自充气alertdialog布局的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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