android UI控件

本文详细探讨了Android应用开发中的关键组件及使用技巧,包括布局管理、列表展示、文本输入、图片显示、搜索功能实现以及软键盘管理等核心模块。通过实例解析,帮助开发者更好地理解和掌握Android开发精髓。

1,关于text和drawableTop之类的间距

android:drawablePadding="10dp"

java代码里设置自定义的字体颜色

counetdownView.setTextColor(mContext.getColorStateList(R.color.text_pre_white_to_gary));

listView

2,商城分类浏览

列表单选效果

102901_QSTU_2375337.png

去掉分割线103043_o8oK_2375337.png

设置list模式(含多个)101225_uCXg_2375337.png

默认选中第一个101113_LS3A_2375337.png

3,edittext属性

Android:phoneNumber=”true”  //输入电话号
android:maxLength=“50” 字数限制
Android:editable // 是否可编辑
代码中清除焦点-不会改变编辑状态
edittext.clearFocus();
在EditText中软键盘的调起、关闭
android:focusable="false"//禁止获取焦点
在父布局设置以下两个属性,取消默认获取焦点
android:focusable="true" 
android:focusableInTouchMode="true" 
android:cursorVisible="false" 隐藏光标
android:background="#00000000"//不要文本框背景 
android:numeric来控制输入的数字类型,一共有三种分别为integer(正整数)、signed(带符号整数,有正负)和decimal(浮点数)。
软键盘的调起导致原来的界面被挤上去,或者导致界面下面的tab导航被挤上去,解决方法如下
解决方法:
使用Manifest中的Activity的android:windowSoftInputMode的"adjustPan"属性。
另外注意:有关软键盘的问题可参考android:windowSoftInputMode中属性。

(1)EditText有焦点(focusable为true)阻止输入法弹出
 editText=(EditText)findViewById(R.id.txtBody);
   editText.setOnTouchListener(new OnTouchListener(){  
         public boolean onTouch(View v, MotionEvent event){ 
            editText.setInputType(InputType.TYPE_NULL); //关闭软键盘     
            return false;
         }
    });
当EidtText无焦点(focusable=false)时阻止输入法弹出
 InputMethodManager imm =
(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); 
 imm.hideSoftInputFromWindow(editText.getWindowToken(),0);
//关闭键盘(比如输入结束后执行) InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(etEditText.getWindowToken(), 0);
 
//自动弹出键盘
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);
etEditText.requestFocus();//让EditText获得焦点,但是获得焦点并不会自动弹出键盘

,4,用于RecyclerView的adapter刷新数据,只有把新的数据传到adapter里然后notifyDataSetChanged()就可以了,如果数据很多,当然也有针对单条的数据更改

public void refresh(List<Variety> list) {
        mVarietyList = list;
        notifyDataSetChanged();//刷新全部数据
        //notifyItemInserted(1); 新添加一条
        //notifyItemRemoved(1);删除一条
    }

5、ImageView图片位置

http://www.cnblogs.com/pandapan/p/4614837.html

6.如果滑动里嵌套列表,事件冲突 ,如果列表只是用于显示,最简单的就是把列表控件的事件取消

mRecyclerView.setNestedScrollingEnabled(false);

7.SearchView使用,搜索后由展开到关闭(缩小)

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                //query:输入框内容
                //设置两次setIconified是为了让searchView收缩
                searchView.setIconified(true);//设置一次是清空内容
                searchView.setIconified(true);//缩小
                return false;
            }
            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });

 

转载于:https://my.oschina.net/Jieth/blog/596015

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值