Android alertdialog的自定义添加按钮和添加点击
来源:互联网 发布:广联达计价软件 编辑:程序博客网 时间:2024/06/06 04:08
我要做的是一个竖排选择的按钮,上面要有图片,因为才学安卓不久小白一个,本来是做ios开发的因公司需要- -,正好也感兴趣,但是感觉学的好慢,就慢慢总结吧,
先看效果图。(左边是图片,右边是文字)
下面是代码:
TableLayout choose = (TableLayout) getLayoutInflater().inflate(R.layout.choose_purchase_way,null);AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.AlertDialog);//builder.setView(LayoutInflater.from(this).inflate(R.layout.choose_purchase_way,null));builder.setView(choose);builder.setTitle("Choose Payment Method");//builder.setTitle("请选择支付方式");AlertDialog alertDialog = builder.create();Button Button1 = (Button) choose.findViewById(R.id.ib_select1Pay);Button1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {LogUtils.e("AlertDialog","select 1");}});Button Button2 = (Button) choose.findViewById(R.id.ib_select2Pay);Button2.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {LogUtils.e("AlertDialog","select 2");}});alertDialog.show();//alertDialog.getWindow().setLayout(600,800);//上面的方法也可以修改alertdialog 的大小,但是我只需要宽度固定,所以采用下面的方法。WindowManager.LayoutParams lp= alertDialog.getWindow().getAttributes();lp.width=850;//定义宽度//lp.height=800;//定义高度alertDialog.getWindow().setAttributes(lp);
因为实在是太小白了,不确定alertdialog的宽度的话,它会随着title 的长度而改变宽度,考虑到多语言的问题,只能固定最大宽度。
下面是xml文件,一个是布局xml。
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/mol_white"> <Button android:id="@+id/ib_select1Pay" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="30dp" android:drawablePadding="-10dp" android:drawableLeft="@drawable/1_logo" android:text="****" /> <Button android:id="@+id/ib_select2Pay</span>" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="30dp" android:drawablePadding="-30dp" android:drawableLeft="@drawable/2_logo" android:text="*****" /></TableLayout>
android:background="@color/mol_white" 只能设置 内容部分的背景色,
<pre name="code" class="html">android:paddingLeft="30dp" 设置图片距离左边边框的距离
<pre name="code" class="html">android:drawablePadding="-30dp" 文字距离左边图片的距离<span style="white-space:pre"></span>
下面是style的xml文件,这里是改变 alertdialog的样式的关键
<pre name="code" class="html"><style name="AlertDialog" parent="@android:style/Theme.DeviceDefault.Light.Dialog" tools:targetApi="ice_cream_sandwich"> <!-- 这里设置背景为透明,为了隐藏边框 --> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <!-- 这里是修改顶部标题背景颜色,具体颜色自己定,可以是图片 --> <item name="android:topDark">@color/mol_white</item> <!-- 这里是修改内容区域背景颜色 --> <item name="android:centerDark">@color/mol_white</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> </style>
<pre name="code" class="csharp"><pre name="code" class="csharp">最后在说一下,安卓的像素问题,= =一开始设置的时候是按照ios 的像素配置的,我擦,好坑爹,调了好久才发现这个问题。示例中,红色部分左边是图片,右边是文字。一共是两个按钮。查资料查的好辛苦,自己太笨。基于Android studio。
0 0
- Android alertdialog的自定义添加按钮和添加点击
- Android Studio AlertDialog 为对话框添加按钮
- Android 动态添加自定义式样的按钮
- android防止按钮多次点击和添加双击事件
- android 添加对back按钮的处理,点击提示退出
- android studio 添加按钮点击事件的三种方法
- QTabWidget添加自定义的按钮
- AlertDialog 加载自定义布局点击按钮消失的方法
- Android开发--为按钮添加点击事件
- android 通知栏添加按钮点击效果
- 自定义Android Action Bar,标题和按钮可以动态添加
- FckEditor工具栏添加自定义按钮,并实现点击按钮的功能
- 添加按钮点击事件
- 按钮添加点击事件的多种方式
- AlertDialog 自定义布局点击按钮消失方法
- 添加了自定义的编辑和删除按钮
- Android AlertDialog解决点击按钮立即消失的问题
- android alertdialog的按钮点击后不消失
- 欢迎使用CSDN-markdown编辑器
- CDH安装
- http摘要认证
- Android基础之再回顾
- Android之批量加载图片OOM问题解决方案
- Android alertdialog的自定义添加按钮和添加点击
- Spinner
- The serializable class Myplayer does not declare a static final serialVersionUID field of type long
- BZOJ2083: [Poi2010]Intelligence test
- Android Studio库工程上传maven
- mininet安装与使用,wireshark抓包器, iperf网络性能检测
- 保护模式及其编程——实模式与保护模式的切换
- linux 常用命令 (汇总加转载 二 find / less)
- 计算机网络的三种通讯模式(单播,广播,组播)小结