我有一个任务,通过xml更改AlertDialog的宽度和高度,我想让它变成样式,所以我可以使用它easy.And,我需要更改AlertDialog风格的按钮也。可以告诉我一种方法实现target.Thank你非常感激。 PS,我会更好地改变XML实现目标。Android:我如何设置AlertDialog的宽度和高度,以及AlertDialog风格的按钮?
7
A
回答
18
有两种方法1)编程2)通过使用XML布局
1)=======>
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.
(or)
alertDialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = 150;
lp.height = 500;
lp.x=-170;
lp.y=100;
alertDialog.getWindow().setAttributes(lp);
如果你想显示要显示的布局,如Alert dialog
请参见this
2)========>
choose.xml
<TextView
android:id="@+id/img"
android:layout_width="wrap_content"
android:text="@string/choose"
android:textSize="25dp"
android:textColor="#fff"
android:layout_height="50dp"/>
<TableLayout android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical">
<TableRow
android:id="@+id/tr1"
android:orientation="horizontal"
android:layout_margin="10dp">
<ImageView
android:contentDescription="@string/phone"
android:src="@drawable/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/phnText"
android:layout_width="wrap_content"
android:text="@string/phone"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:textColor="#000"
android:layout_height="50dp"/>
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FF000000" />
<TableRow
android:id="@+id/tr2"
android:orientation="horizontal"
android:layout_margin="10dp">
<ImageView
android:contentDescription="@string/sms"
android:src="@drawable/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/smsText"
android:layout_width="wrap_content"
android:text="@string/sms"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:textColor="#000"
android:layout_height="50dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
显示这是弹出像下面
private void showPopUp()
{
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("");
LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.choose, null);
helpBuilder.setView(checkboxLayout);
final AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
TableRow tablerowPhone = (TableRow)checkboxLayout.findViewById(R.id.tr1);
TableRow tablerowSms = (TableRow)checkboxLayout.findViewById(R.id.tr2);
tablerowPhone.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
helpDialog.dismiss();
Uri callUri = Uri.parse("tel:" + listview_array[4]);
Intent intent = new Intent(Intent.ACTION_CALL, callUri);
startActivity(intent);
}
});
tablerowSms.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
helpDialog.dismiss();
Uri smsUri = Uri.parse("sms:" + listview_array[4]);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
startActivity(intent);
}
});
}
电话,你想要这个showPopUp()
方法。这样就可以设置高度和宽度在XML文件中的布局
+0
非常感谢。这种方式可以做到,但我想用xml文件来做。因为我想配置XML到我的application.do你有办法做到这一点的XML文件?谢谢你一遍又一遍。 – oldfox3721 2012-08-09 03:06:22
1
试试这个,这对我的作品,
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.
alertDialog.show();
相关问题
- 1. 高度的AlertDialog
- 2. 如何设置AlertDialog项目高度?
- 3. 如何在Android中为按钮设置宽度和高度?
- 4. 如何获得AlertDialog的高度在Android
- 5. 设置按钮的高度与宽度
- 6. 如何设置相同的宽度和高度的按钮
- 7. 如何设置单选按钮的高度和宽度?
- 8. AlertDialog程序兼容性的宽度和高度
- 9. 的Android AlertDialog与自定义宽度
- 10. AlertDialog有太大的文字和宽度
- 11. 错误的宽度/高度充气XML中的AlertDialog
- 12. 动态设置按钮的宽度和高度
- 13. Android AlertDialog单按钮
- 14. tkinter按钮的高度和宽度
- 15. 如何设置ImageView的高度和宽度活动的Android
- 16. 的Android AlertDialog按钮定位
- 17. 设置按钮高度等于按钮宽度
- 18. 如何在HTML表格中设置Tbody的宽度和高度
- 19. 设置画布高度和宽度的高度以及包含分区的宽度
- 20. 如何在AS3中设置我的swf的宽度和高度?
- 21. 自定义高度和宽度在自定义充气alertdialog布局android
- 22. 如何设置android评级栏的高度和宽度?
- 23. 在Android中,如何设置ListView项目的高度和宽度?
- 24. 如何设置jqModal的高度宽度?
- 25. 我将如何设置noty通知的高度和宽度
- 26. 我们如何设置影片剪辑的宽度和高度?
- 27. 我如何设置浏览弹窗的宽度和高度?
- 28. 我可以设置href的宽度和高度100%
- 29. 按钮宽度,高度
- 30. 设置手风琴的宽度和高度
你可以有这样的事情http://stackoverflow.com/questions/1979369/ android-activity-as-a-dialog – 2012-08-08 02:18:30
@ userIsAMonkey,非常感谢你,我已经考虑过使用Activity作为对话框,但它对我的任务使用对话框很有帮助。因为有很多对话等待显示。我们希望有一种方式可以很容易地显示。谢谢你,别的。 – oldfox3721 2012-08-09 01:19:14