安卓常用模块收集(一)--编辑窗口
来源:互联网 发布:极限挑战 感情 知乎 编辑:程序博客网 时间:2024/06/11 21:24
////////////////////////2016/09/23//////////////////////
//////////////////////////by xbw////////////////////////
最近发现安卓里的好多模块都能重复使用,避免麻烦收集一下常用的布局等
如图,编辑模块,我们在修改个人信息时,大多会需要这个,,,,
先上布局文件
edit_text_info_window.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/vBaseBottomWindowRoot" style="@style/bottom_window_page" > <RelativeLayout style="@style/topbar_bg" android:background="@color/white" > <TextView android:id="@+id/tvEditTextInfoTitle" style="@style/topbar_title" android:layout_centerHorizontal="true" android:text="编辑" android:textColor="@color/black" android:textSize="20sp" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="@dimen/common_item_distance" android:background="@color/white" /> <TextView android:id="@+id/tvEditTextInfoPlace" style="@style/text_middle_blue" android:layout_width="match_parent" android:background="@drawable/bg_white_to_gray" android:gravity="center_vertical|left" android:hint="点击选择地址" android:paddingBottom="12dp" android:paddingLeft="@dimen/common_item_left_tv_padding" android:paddingRight="@dimen/common_item_right_img_padding_right" android:paddingTop="6dp" android:visibility="gone" /> <LinearLayout style="@style/edit_item" > <LinearLayout style="@style/edit_item_right_et" android:layout_marginLeft="@dimen/common_item_left_tv_padding" android:layout_weight="1" android:orientation="vertical" > <EditText android:id="@+id/etEditTextInfo" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="3dp" android:layout_weight="1" android:background="@null" android:cursorVisible="true" android:gravity="center|left" android:hint="请在这里输入" android:maxLength="30" android:paddingRight="10dp" android:textColor="@color/black" android:textCursorDrawable="@drawable/edit_cusor" android:textSize="17sp" > <requestFocus /> </EditText> <View style="@style/divider_horizontal_1dp" android:background="@color/green" /> </LinearLayout> <ImageView android:id="@+id/ivEditTextInfoClear" style="@style/edit_item_right_clear" android:layout_width="wrap_content" android:visibility="gone" /> </LinearLayout> <TextView android:id="@+id/tvEditTextInfoRemind" style="@style/content_item_remind_tv" android:layout_height="wrap_content" android:background="@color/white" android:paddingBottom="30dp" android:paddingTop="@dimen/common_item_padding_bottom" android:text="您还可以输入" /> <View style="@style/divider_horizontal_1px_gray" /> <LinearLayout style="@style/ll_horizontal_match_wrap" android:background="@color/white" > <TextView android:id="@+id/tvEditTextInfoReturn" style="@style/bottom_menu_btn_cancel" android:layout_weight="1" /> <View style="@style/divider_vertical_1px_gray" /> <TextView android:id="@+id/tvEditTextInfoForward" style="@style/bottom_menu_btn_save" android:layout_weight="1" /> </LinearLayout></LinearLayout>
styles.xml
<style name="activity_page"> <item name="android:splitMotionEvents">false</item> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">fill_parent</item> <item name="android:background">@color/activity_bg</item> <item name="android:orientation">vertical</item> </style> <style name="bottom_window_page" parent="activity_page"> <item name="android:gravity">bottom|center_horizontal</item> <item name="android:background">@color/alpha_complete</item> </style> <style name="topbar_bg"> <item name="android:background">@color/topbar_bg</item> <item name="android:gravity">center_vertical</item> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">@dimen/topbar_height</item> </style> <style name="topbar_title"> <item name="android:textColor">@color/black</item> <item name="android:gravity">center</item> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">match_parent</item> <item name="android:textSize">18sp</item> </style> <style name="wrap_wrap"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style> <style name="text" parent="wrap_wrap"> <item name="android:gravity">center</item> <item name="android:textColor">@color/gray_3</item> </style> <style name="text_middle" parent="text"> <item name="android:textSize">@dimen/text_size_middle</item> </style> <style name="text_middle_blue" parent="text_middle"> <item name="android:textColor">@color/blue</item> </style> <style name="edit_item"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">50dp</item> <item name="android:background">@color/white_selected</item> <item name="android:gravity">center_vertical</item> <item name="android:orientation">horizontal</item> </style> <style name="edit_item_right_et" parent="edit_item"> <item name="android:layout_width">0dp</item> <item name="android:layout_height">match_parent</item> <item name="android:background">@null</item> <item name="android:gravity">center|left</item> <item name="android:paddingRight">10dp</item> <item name="android:maxLength">24</item> <item name="android:singleLine">true</item> <item name="android:textColor">@color/black</item> <item name="android:textSize">17sp</item> </style> <style name="divider_horizontal_1dp" parent="divider"> <item name="android:layout_height">1dp</item> <item name="android:layout_width">fill_parent</item> </style> <style name="edit_item_right_clear"> <item name="android:layout_width">30dp</item> <item name="android:layout_height">match_parent</item> <item name="android:src">@drawable/cancel_light</item> <item name="android:textSize">@dimen/text_size_middle</item> <item name="android:textColor">@color/gray</item> <item name="android:gravity">center</item> <item name="android:paddingRight">@dimen/common_item_padding_right</item> </style> <style name="content_item_remind_tv"> <item name="android:layout_height">@dimen/common_item_remind_tv_height</item> <item name="android:layout_width">match_parent</item> <item name="android:textSize">14sp</item> <item name="android:textColor">@color/gray_1</item> <item name="android:gravity">center_vertical</item> <item name="android:paddingLeft">@dimen/common_item_left_tv_padding</item> <item name="android:paddingRight">@dimen/common_item_right_img_padding_right</item> </style> <style name="divider_horizontal_1px" parent="divider"> <item name="android:layout_height">1px</item> <item name="android:layout_width">fill_parent</item> </style> <style name="divider_horizontal_1px_gray" parent="divider_horizontal_1px"> <item name="android:background">@color/gray_2</item> </style> <style name="match_wrap"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> </style> <style name="ll_horizontal_match_wrap" parent="match_wrap"> <item name="android:gravity">center_vertical</item> <item name="android:orientation">horizontal</item> </style> <style name="bottom_menu_btn_cancel" parent="bottom_menu_btn"> <item name="android:text">取消</item> <item name="android:textColor">@color/gray_3</item> </style> <style name="divider"> <item name="android:background">@color/alpha_3</item> </style> <style name="divider_vertical_1px" parent="divider"> <item name="android:layout_width">1px</item> <item name="android:layout_height">fill_parent</item> </style> <style name="divider_vertical_1px_gray" parent="divider_vertical_1px"> <item name="android:background">@color/gray_2</item> </style> <style name="bottom_menu_btn"> <item name="android:layout_width">0dp</item> <item name="android:layout_height">wrap_content</item> <item name="android:padding">@dimen/btn_bottom_padding</item> <item name="android:background">@drawable/bg_item_to_alpha</item> <item name="android:textSize">20sp</item> <item name="android:textColor">@color/black</item> <item name="android:gravity">center</item> </style> <style name="bottom_menu_btn_save" parent="bottom_menu_btn"> <item name="android:text">保存</item> </style>
dimens.xml
<!-- 分割线高度 --> <dimen name="line_height">1dp</dimen> <dimen name="topbar_height">50dp</dimen> <dimen name="common_item_distance">15dp</dimen> <dimen name="common_item_left_tv_padding">15dp</dimen> <dimen name="common_item_right_img_padding_right">15dp</dimen> <dimen name="text_size_middle">16sp</dimen> <dimen name="common_item_padding_right">12dp</dimen> <dimen name="common_item_remind_tv_height">30dp</dimen> <dimen name="common_item_padding_bottom">15dp</dimen> <dimen name="btn_bottom_padding">10dp</dimen>
colors.xml
<!-- 控件按下时显示的颜色 --> <color name="list_backgroud_color">#2fb3cb</color> <color name="title_color">#0f8ec5</color> <color name="content_color">#737373</color> <color name="alpha_complete">#0000</color> <color name="topbar_bg">#33cc99</color> <color name="divider">#dddddd</color> <color name="white_selected">#ffffff</color> <color name="green">#33cc66</color> <color name="gray">#666666</color> <color name="gray_1">#b5b5b5</color> <color name="gray_2">#999999</color> <color name="gray_3">#666666</color> <color name="alpha_1">#1000</color> <color name="alpha_3">#3000</color> <color name="activity_bg">#f7f8f8</color> <drawable name="transparent_background">#00000000</drawable> <color name="black"> #000000</color> <color name="blue">#68217A</color>
drawable文件
bg_item_to_alpha.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/alpha_1" android:state_pressed="true"/> <item android:drawable="@color/alpha_1" android:state_focused="true"/></selector>bg_white_to_gray.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/divider" android:state_pressed="true"/> <item android:drawable="@color/white"/></selector>edit_cusor.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@color/green" /> <size android:width="1dp" /></shape>cancle_light.png图片资源
窗口封装起来了
根据自己的需要修改
package com.xbw.danmu.danmu;import android.app.AlertDialog;import android.app.Dialog;import android.content.Context;import android.graphics.Color;import android.text.Editable;import android.text.TextWatcher;import android.view.LayoutInflater;import android.view.View;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.ImageButton;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.TextView;import java.util.Random;public class ChangeDialog {private EditText edit;private TextView charnum_tx;private int charnum = 15;Context context;public ChangeDialog(Context context) {this.context=context;}public void showChangeDialog(String contexts) {LayoutInflater layoutInflater = LayoutInflater.from(context);LinearLayout layout = (LinearLayout) layoutInflater.inflate(R.layout.edit_text_info_window, null);final Dialog dialog = new AlertDialog.Builder(context).create();dialog.show();dialog.getWindow().setContentView(layout);dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);TextView tex1 = (TextView) layout.findViewById(R.id.tvEditTextInfoTitle);tex1.setText("昵称");edit = (EditText) layout.findViewById(R.id.etEditTextInfo);edit.setHint(contexts);//edit.setSelection(edit.length());edit.addTextChangedListener(myWatcher);charnum_tx = (TextView) layout.findViewById(R.id.tvEditTextInfoRemind);TextView btnOK = (TextView) layout.findViewById(R.id.tvEditTextInfoForward);btnOK.setText("确认");btnOK.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if (edit.getText().length() > 15) {} else if(edit.getText().toString()==null) {String[] username= {"儿子","孙子","狗","猪","许","哈哈","滚","Q","SB"};Random random = new Random();int p = random.nextInt(username.length);Config.UserName=username[p];}else {Config.UserName=edit.getText().toString();}dialog.dismiss();}});// 关闭按钮TextView btnClose = (TextView) layout.findViewById(R.id.tvEditTextInfoReturn);btnClose.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {String[] username= {"儿子","孙子","狗","猪","许","哈哈","滚","Q","SB"};Random random = new Random();int p = random.nextInt(username.length);Config.UserName=username[p];dialog.dismiss();}});}TextWatcher myWatcher = new TextWatcher() {@Overridepublic void afterTextChanged(Editable s) {int len = charnum - edit.getText().length();if (len >= 0)charnum_tx.setText("您还可以输入" + len + " \\ " + charnum);elsecharnum_tx.setText("字数超限");}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before,int count) {}};}
0 0
- 安卓常用模块收集(一)--编辑窗口
- 安卓项目实战----收集用户信息(一)
- Python 常用模块收集
- NodeJS常用模块收集
- 安卓之窗口机制初涉(一)
- 安卓常用控件一
- 安卓代码中常用的代码以及问题收集
- 常用正则表达式模式收集(一)
- 安卓经验收集(不断更新)
- 安卓网站收集
- 安卓博客收集
- 安卓源码收集
- Yii-modules模块- 配置收集
- Python常用模块学习(一)
- 安卓Hook系列教程(一):xposed模块开发环境搭建
- 安卓Hook系列教程(一):xposed模块开发环境搭建
- 安卓窗口显示
- 安卓窗口相关
- 原始套接字编程
- 用户界面UI -- 客户端 -- 数据库 交互时时间保护
- 23. Merge k Sorted Lists(heap)
- SQL实现一个表格中多个字段合并为一个字段
- android studio 错误的解决方法之一:transformClassesWithDexForDebug' finished with non-zero exit value 3
- 安卓常用模块收集(一)--编辑窗口
- CentOS vsftp 553 Could not create file 错误解决
- 堆栈数据代码区
- 不使用第三个结点实现单链表的逆转
- 秒杀设计方案讨论
- PAT(A) - 1094. The Largest Generation (25)
- ios 几种线程依赖的处理方式
- RMAN异地恢复
- 微信小程序将带来web程序员的春天!