edittext Android ui优化

来源:互联网 发布:王者荣耀用java还是c 编辑:程序博客网 时间:2024/06/06 18:40

1.编辑完 点击下一步 到另一个edittext

设置3个属性:
android:singleLine=”true”
android:imeOptions=”actionNext”
android:nextFocusForward=”@+id/et_pwd”

 <LinearLayout        android:id="@+id/login_info"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="20dp"        android:layout_marginRight="20dp"        android:layout_marginTop="30dp"        android:gravity="center_horizontal"        android:orientation="vertical" >        <EditText            android:id="@+id/et_user"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginBottom="@dimen/common_drawablePadding5"            android:gravity="center_vertical"            android:textCursorDrawable="@drawable/shape_edittext_cursor"            android:singleLine="true"            android:hint="请输入账号"            android:drawableLeft="@mipmap/ic_persion"            android:drawablePadding="15dp"            android:background="@null"            android:textColorHint="@color/login_color"            android:textColor="@color/login_color"            android:textSize="@dimen/text14"            android:imeOptions="actionNext"           android:nextFocusForward="@+id/et_pwd"            />        <View            android:layout_width="match_parent"            android:layout_height="1dp"            android:background="@color/login_color"></View>        <EditText            android:id="@+id/et_pwd"            android:layout_marginTop="@dimen/common_drawablePadding20"            android:layout_marginBottom="@dimen/common_drawablePadding5"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center_vertical"            android:singleLine="true"            android:drawableLeft="@mipmap/ic_lock"            android:textCursorDrawable="@drawable/shape_edittext_cursor"            android:drawablePadding="15dp"            android:hint="请输入密码"            android:background="@null"            android:inputType="textPassword"            android:textColorHint="@color/login_color"            android:textColor="@color/login_color"            android:textSize="@dimen/text14"            />        <View            android:layout_width="match_parent"            android:layout_height="1dp"            android:background="@color/login_color"></View>    </LinearLayout>

2.edittext 要求被输入法顶起来

activity里:代码,
布局参考上面的代码;

//加入滚动        mInputLayout = (LinearLayout) findViewById(R.id.login_info);        rLayout = ((LinearLayout) findViewById(R.id.root));        //输入法到底部的间距(按需求设置)        final int paddingBottom = DisplayUtil.dp2px(this, 5);        rLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {            @Override            public void onGlobalLayout() {                Rect r = new Rect();                rLayout.getWindowVisibleDisplayFrame(r);                //r.top 是状态栏高度                int screenHeight = rLayout.getRootView().getHeight();                int softHeight = screenHeight - r.bottom ;                Log.e("test","screenHeight:"+screenHeight);                Log.e("test","top:"+r.top);                Log.e("test","bottom:"+r.bottom);                Log.e("test", "Size: " + softHeight);                if (softHeight>100){//当输入法高度大于100判定为输入法打开了                    rLayout.scrollTo(0, softHeight+paddingBottom);                }else {//否则判断为输入法隐藏了                    rLayout.scrollTo(0, paddingBottom);                }            }        });
原创粉丝点击