- 浏览: 544369 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
tangyunliang:
大哥你太历害了谢谢
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
u013015029:
LZ,请问下,在// 添加消息到聊天窗口 , 这里获取Ed ...
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
endual:
怎么保持会话,我搞不懂啊
Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器 -
donala_zq:
显示:[2013-11-30 11:50:36 - Andro ...
android-----------新浪微博 -
donala_zq:
哥,运行不了啊
android-----------新浪微博
Android默认的PopupWindow和EditText的外观是矩形框,看起来不是太好,本示例通过设置布局View的背景和PopupWindowd对象的背景,实现有白色圆角边框的对话框效果和圆角文字编辑框。代码如下(关键部分是背景布局XML)
效果图:
[img]
[/img]
工程结构图:
[img]
[/img]
Activity:
rounded_corners_pop.xml:
rounded_corners_view.xml
rounded_edittext_states.xml
rounded_edittext.xml
rounded_focused.xml
popupwindow.xml
效果图:
[img]

[/img]
工程结构图:
[img]

[/img]
Activity:
package com.test; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.text.InputType; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.PopupWindow; import android.widget.LinearLayout.LayoutParams; public class RoundCorner extends Activity { Button mButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 定义按钮 mButton = (Button) this.findViewById(R.id.Button01); mButton.setOnClickListener(new ClickEvent()); // 两个圆角文字编辑框 EditText et1 = (EditText) this.findViewById(R.id.roundedtext1); EditText et2 = (EditText) this.findViewById(R.id.roundedtext2); et1.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); et2.setInputType(InputType.TYPE_NULL); //不显示软键盘 } // 处理按键事件 class ClickEvent implements OnClickListener { @Override public void onClick(View v) { if (v == mButton) { showRoundCornerDialog(RoundCorner.this, RoundCorner.this.findViewById(R.id.Button01)); } } } // 显示圆角对话框 public void showRoundCornerDialog(Context context, View parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // 获取圆角对话框布局View,背景设为圆角 final View dialogView = inflater.inflate(R.layout.popupwindow, null, false); dialogView.setBackgroundResource(R.drawable.rounded_corners_view); // 创建弹出对话框,设置弹出对话框的背景为圆角 final PopupWindow pw = new PopupWindow(dialogView, 300, LayoutParams.WRAP_CONTENT, true); pw.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_pop)); //注:上面的设背景操作为重点部分,可以自行注释掉其中一个或两个设背景操作,查看对话框效果 //注:上面的设背景操作为重点部分,可以自行注释掉其中一个或两个设背景操作,查看对话框效果 final EditText edtUsername = (EditText) dialogView.findViewById(R.id.username_edit); final EditText edtPassword = (EditText) dialogView.findViewById(R.id.password_edit); edtUsername.setHint("用户名..."); // 设置提示语 edtPassword.setHint("密码..."); // 设置提示语 // OK按钮及其处理事件 Button btnOK = (Button) dialogView.findViewById(R.id.BtnOK); btnOK.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 设置文本框内容 edtUsername.setText("username"); edtPassword.setText("password"); } }); // Cancel按钮及其处理事件 Button btnCancel = (Button) dialogView.findViewById(R.id.BtnCancel); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pw.dismiss();// 关闭 } }); // 显示RoundCorner对话框 pw.showAtLocation(parent, Gravity.CENTER|Gravity.BOTTOM, 0, 0); } }
rounded_corners_pop.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffffff" /> <stroke android:width="3dp" color="#ffff8080" /> <corners android:radius="10dp" /> <padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" /> </shape>
rounded_corners_view.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ff606060" /> <stroke android:width="3dp" color="#ffff8080" /> <corners android:radius="10dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape>
rounded_edittext_states.xml
<?xml version="1.0" encoding="utf-8"?> <!-- res/drawable/rounded_edittext_states.xml --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/rounded_focused" /> <item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/rounded_focused" /> <item android:state_enabled="true" android:drawable="@drawable/rounded_edittext" /> </selector>
rounded_edittext.xml
<?xml version="1.0" encoding="utf-8"?> <!-- res/drawable/rounded_edittext.xml --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="8dip"> <solid android:color="#FFFFFF"/> <corners android:bottomRightRadius="10dip" android:bottomLeftRadius="10dip" android:topLeftRadius="10dip" android:topRightRadius="10dip"/> </shape>
rounded_focused.xml
<?xml version="1.0" encoding="utf-8"?> <!-- res/drawable/rounded_edittext_focused.xml --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="8dip"> <solid android:color="#FFFFFF"/> <stroke android:width="2dip" android:color="#FF0000" /> <corners android:bottomRightRadius="10dip" android:bottomLeftRadius="10dip" android:topLeftRadius="10dip" android:topRightRadius="10dip"/> </shape>
popupwindow.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/username_view" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:text="用户名" android:textAppearance="?android:attr/textAppearanceMedium"/> <EditText android:id="@+id/username_edit" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:capitalize="none" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/password_view" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:text="密码" android:textAppearance="?android:attr/textAppearanceMedium"/> <EditText android:id="@+id/password_edit" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:capitalize="none" android:password="true" android:textAppearance="?android:attr/textAppearanceMedium" /> <LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center" android:paddingLeft="10dip" android:paddingRight="10dip"> <Button android:id="@+id/BtnOK" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="确定"/> <Button android:id="@+id/BtnCancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消"/> </LinearLayout> </LinearLayout>
发表评论
-
Android中如何模拟一次点击(touch)事件
2014-05-06 10:41 0在Android中有时需要模拟某一个View的touch事件, ... -
Android程序Crash时的异常上报
2014-04-28 18:15 0http://blog.csdn.net/singwhatiw ... -
android程序中证书签名校验的方法
2014-04-28 17:58 2041android程序中证书签名校验的方法一 2013-02 ... -
MD5理解错了,哎
2014-03-17 14:14 0MD5只对数据加密是无法解密的,也就是说,你把100加密后,就 ... -
Android 获取网络时间
2014-03-12 11:42 2056Android 获取网络时间 在网上看到的最常见的方式有: ... -
SQLite清空表并将自增列归零
2014-03-05 18:02 1582SQLite清空表并将自增列归零 作者:Zhu Yanfeng ... -
Handler小看一下
2013-11-11 16:42 0android handler调用post方法还是阻塞 su ... -
Frame Animation小看一下
2013-10-12 16:30 842Demo运行效果图: 源码: -
动画小学一下
2013-10-12 16:14 766转自: http://www.eoeandroid.com/f ... -
Android 动画之ScaleAnimation应用详解
2013-10-12 15:49 1046===============eoeAndroid社区推荐:= ... -
android开发中的一个工具类
2013-06-19 16:04 0package com.wanpu.login.dialog; ... -
android TextView怎么设置个别字体颜色并换行?
2013-06-20 09:25 1729(1)、TextView 设置个别字体颜色 TextView ... -
Android开发之文件下载,状态时显示下载进度,点击自动安装
2013-05-07 15:38 1480在进行软件升级时,需要进行文件下载,在这里实现自定义的文件下载 ... -
android中的状态保存
2013-04-07 14:21 996package com.zzl.call; import ... -
android动画基础:tween动画
2013-04-06 11:21 1292工程结构图: [img] [/img] 四个动画的xml ... -
面试中遇到的几个问题
2013-06-09 11:56 1054SAX与DOM之间的区别 SAX ( ... -
Android获取其他包的Context实例,然后调用它的方法,反射!!!
2013-03-25 10:32 1244Android中有Context的概念,想必大家都知道。Con ... -
Android的内存机制和常见泄漏情形
2013-03-06 16:55 836一、 Android的内存机制 Android的程序由Ja ... -
JUnit测试小小demo
2013-03-06 16:37 1215运行效果图: [img] [/img] 项目结构图 ... -
android开发中的异常小工具
2013-03-04 15:53 919package com.zzl.tools; impor ...
相关推荐
5. **防止PopupWindow遮挡输入法**:如果PopupWindow下方有EditText,可能会影响到输入法的显示。这时可以通过`setSoftInputMode()`设置调整输入法模式,如`SOFT_INPUT_ADJUST_RESIZE`或`SOFT_INPUT_ADJUST_PAN`,...
5. **弹窗效果**:在支付宝和微信支付中,输入框通常是弹出式的对话框,这需要用到`DialogFragment`或者自定义的`PopupWindow`来实现。在弹出框中放置自定义的EditText,并处理其显示和关闭逻辑。 6. **动画效果**...
源代码中可能包括自定义的EditText样式,如圆角边框,以及登录按钮的点击动画效果。此外,安全因素也非常重要,例如密码输入时的星号隐藏或眼睛图标切换显示。 其次,QQ列表显示。在Android中,列表通常通过...
在类中,我们可以定义六个TextView(而非EditText)来表示密码的每一位,并设置它们的默认样式,如大小、颜色和字体。同时,需要重写`onTouchEvent`方法来监听用户的触摸事件。 2. **布局设计**: 在XML布局文件中...