android 自定义单选框样式,android – 自定义对话框,其中包含单选列表项

创建自定义对话框的步骤:

>创建对话框布局文件,如:

android:layout_width = "wrap_content"

android:layout_height = "wrap_content">

android:id="@+id/dlg_priority_titlebar"

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentTop="true">

android:src="@drawable/image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="5dip" />

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:text = "Select Task Priority"

android:layout_gravity = "center_vertical" />

android:id="@+id/dlg_priority_lvw"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/dlg_priority_titlebar"

android:background="@drawable/layout_home_bg">

>因为ListView中的布局是自定义的,所以要为ListView创建一个布局文件:

android:orientation = "horizontal"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent">

android:id = "@+id/list_priority_img"

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:layout_gravity = "center_vertical"

android:layout_margin = "5dip" />

android:id = "@+id/list_priority_value"

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:layout_gravity = "center_vertical"

android:textsize = "28dip"

android:textColor = "@drawable/ black" />

>创建从Dialog继承的自定义Dialog类PriorityDlg

公共类PriorityDlg扩展Dialog {

private Context context;

private ListView dlg_priority_lvw = null;

public PriorityDlg(Context context) {

super(context);

this.context = context;

// TODO Auto-generated constructor stub

}

public PriorityDlg(Context context, int theme) {

super(context, theme);

this.context = context;

}

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

this.setContentView(R.layout.dlg_priority);

dlg_priority_lvw = (ListView) findViewById(R.id.dlg_priority_lvw);

// ListView

SimpleAdapter adapter = new SimpleAdapter(context, getPriorityList(),

R.layout.lvw_priority, new String[] { "list_priority_img",

"list_priority_value" }, new int[] {

R.id.list_priority_img, R.id.list_priority_value });

dlg_priority_lvw.setAdapter(adapter);

//ListView

dlg_priority_lvw

.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView> arg0, View arg1,

int arg2, long arg3) {

}

});

}

private List> getPriorityList() {

List> priorityList = new ArrayList>();

HashMap map1 = new HashMap();

map1.put("list_priority_img", R.drawable.priority_not_important);

map1.put("list_priority_value", context.getResources().getString(

R.string.dlg_priority_not_important));

priorityList.add(map1);

HashMap map2 = new HashMap();

map2.put("list_priority_img", R.drawable.priority_general);

map2.put("list_priority_value", context.getResources().getString(

R.string.dlg_priority_general));

priorityList.add(map2);

HashMap map3 = new HashMap();

map3.put("list_priority_img", R.drawable.priority_important);

map3.put("list_priority_value", context.getResources().getString(

R.string.dlg_priority_important));

priorityList.add(map3);

HashMap map4 = new HashMap();

map4.put("list_priority_img", R.drawable.priority_very_important);

map4.put("list_priority_value", context.getResources().getString(

R.string.dlg_priority_very_important));

priorityList.add(map4);

return priorityList;

}

}

>创建自定义对话框

PriorityDlg dlg = new PriorityDlg (SimpleTaskActivity.this, R.style.dlg_priority);

dlg.show();

R.style.dlg_priority设置对话框使用样式文件,只需让对话框删除标题栏,当然你可以编写代码来完成这个效果:

Xml version = "1.0" encoding = "utf-8"?>

true item>

style>

resources>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值