自定义dialog的布局样式
2014-03-12 00:49
381 查看
(written at
2014-02-08 17:08:09)
在网上找了很多关于dialog的自定义样式的问题,还有很多人写得比较复杂,需要改动style什么的,或者是自定义dialog搞得很复杂,我最后还是找到了方法来实现。参考原文地址:http://jy0329.blog.163.com/blog/static/14746600220132204035120/
下面是我的dialog布局xml文件:
效果如图:
![](http://s7.sinaimg.cn/mw690/001niEbAgy6GqDjniWq86&690)
在代码中需要这项写就可以了:
非常easy!自己动手吧。
2014-02-08 17:08:09)
在网上找了很多关于dialog的自定义样式的问题,还有很多人写得比较复杂,需要改动style什么的,或者是自定义dialog搞得很复杂,我最后还是找到了方法来实现。参考原文地址:http://jy0329.blog.163.com/blog/static/14746600220132204035120/
下面是我的dialog布局xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" android:layout_margin="50dp"> <RelativeLayout android:id="@+id/rl_dialog_content" android:layout_width="fill_parent" android:layout_height="200dp" android:background="@drawable/alertdialog_bg"> <</span>TextView android:id="@+id/dialog_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="现在就打电话给客服:arjinmc" android:layout_marginTop="50dp" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:maxLines="5" android:gravity="center" /> <LinearLayout android:id="@+id/ll_buttons" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true" android:layout_margin="30dp"> <Button android:id="@+id/dialog_cancel" android:text="@string/alert_cancel" android:background="@drawable/btn_long_white" style="@style/dialog_button" android:layout_weight="1" android:textColor="@color/tabs_font" /> <Button android:id="@+id/dialog_ok" android:text="@string/alert_ok" android:background="@drawable/btn_long_red" style="@style/dialog_button" android:layout_weight="1" android:layout_marginLeft="5dp"/> </LinearLayout> </RelativeLayout> <ImageButton android:id="@+id/dialog_close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/alertdialog_close" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginLeft="20dp" /> </RelativeLayout>
效果如图:
在代码中需要这项写就可以了:
//布局文件转换为view对象 LayoutInflater inflaterDl = LayoutInflater.from(this); RelativeLayout layout = (RelativeLayout)inflaterDl.inflate(R.layout.layout_dialog, null ); //对话框 final Dialog dialog = newAlertDialog.Builder(SettingActivity.this).create(); dialog.show(); dialog.getWindow().setContentView(layout); //取消按钮 Button btnCancel = (Button) layout.findViewById(R.id.dialog_cancel); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "cancel", Toast.LENGTH_SHORT).show(); } }); //确定按钮 Button btnOK = (Button) layout.findViewById(R.id.dialog_ok); btnOK.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show(); } }); //关闭按钮 ImageButton btnClose = (ImageButton) layout.findViewById(R.id.dialog_close); btnClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } });
非常easy!自己动手吧。
相关文章推荐
- Table样式设置
- css滑动门实现
- div+css
- css中的选择器
- DIV内容不可以点击[模仿126邮箱地址样式]
- CSS3----border-sizing
- 前台按钮样式
- DIV重叠 CSS让DIV层叠 两个DIV或多个DIV顺序重叠加
- CSS3----background:-webkit-gradient()渐变效果
- CSS中的中文乱码问题
- 【经验】在CSS中定义a:link、a:visited、a:hover、a:active顺序
- CSS选择器
- DIV层+CSS实现锁屏
- JAVA 单选样式编写
- 关于CSS的display属性的探究
- 编写跨浏览器兼容的 CSS 代码的金科玉律
- CSS3.0盒模型display:-webkit-box;的使用
- css在div块添加背景图片为何不显示呢?
- CSS初学
- 实战中总结出来的CSS常见问题及解决办法