Android:关于Edittext的一些设置

1.自动弹出输入框.

  et_order_search.setFocusableInTouchMode(true);
            et_order_search.requestFocus();
            CmzBossApplication.handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager inputManager = (InputMethodManager) et_order_search.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputManager.showSoftInput(et_order_search, 0);
                }
            }, 200);

2.不显示下划线 ,光标颜色设置.

            <EditText
                android:textCursorDrawable="@drawable/color_cursor"//这里只能是drawable,不能直接设置color;如果不设置则默认是红色的光标,但是设置成@null,颜色会和字体颜色一致,但是位置不对.
                android:id="@+id/aof_et_orderSearch"
                android:background="@null"
                android:singleLine="true"
                android:textColor="@color/blue_l"
                android:textColorHint="@color/blue_l"
                android:hint="请输入订单号"
                android:gravity="center"
                android:layout_marginRight="52dp"
                android:layout_marginLeft="@dimen/dp20"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

3.光标颜色设置

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <size android:width="1dp" />
    <solid android:color="@color/blue_l"  />
</shape>

4.EditText会把整个布局网上顶,有时候我们需要这种,但是有时候却不需要.所以需要设置Activity的一些属性.

 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);//不让输入法往上顶!
        setContentView(R.layout.activity_order_form_layout);
_______________________________________________________________________________________________________________________________________________ getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//输入法往上顶. setContentView(R.layout.activity_order_form_layout);

 5.dialog中弹出键盘.获取焦点的代码.

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);

posted on 2017-01-12 14:06  放纵的卡尔  阅读(758)  评论(0编辑  收藏  举报

导航