不废话,先爆照






让EditText不现实光标

关键代码:
android:focusable="true"android:focusableInTouchMode="true"

写这个父视图里面
下面是全部代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"                xmlns:tools="http://schemas.android.com/tools"                android:layout_width="match_parent"                android:layout_height="match_parent"                tools:context=".HomeActivity"><RelativeLayoutandroid:id="@+id/rl_search"android:layout_width="match_parent"android:layout_height="wrap_content"android:focusable="true"android:focusableInTouchMode="true"android:background="@color/greyBe"android:paddingTop="4dp"android:paddingBottom="4dp"android:paddingLeft="8dp"android:paddingRight="8dp"><RelativeLayoutandroid:id="@+id/bt_nearby_search"android:layout_width="match_parent"android:layout_height="35dp"android:layout_centerInParent="true"android:background="@drawable/bg_search"android:padding="4dp"android:gravity="center"><Buttonandroid:id="@+id/btn_search_icon"android:layout_width="16dp"    android:layout_height="16dp"android:layout_centerVertical="true"android:background="@mipmap/icon_search"android:clickable="false" /><Buttonandroid:layout_width="match_parent"    android:layout_height="25dp"    android:id="@+id/home_search"android:layout_toRightOf="@+id/btn_search_icon"android:layout_centerVertical="true"android:background="@null"android:textSize="12sp"android:hint="@string/search_hint"/></RelativeLayout></RelativeLayout><com.kuyu.kuyucontact.ui.view.PinnedSectionListViewandroid:id="@+id/lv_contact"android:layout_toLeftOf="@+id/v_line"android:layout_below="@+id/rl_search"android:layout_width="match_parent"android:layout_height="wrap_content"android:scrollbars="none" /><TextViewandroid:id="@+id/tv_float_letter"android:layout_width="80dp"android:layout_height="80dp"android:background="#F88701"android:gravity="center"android:layout_centerInParent="true"android:textSize="40sp"android:visibility="gone" /><Viewandroid:id="@+id/v_line"android:layout_width="1dp"android:layout_height="match_parent"android:layout_toLeftOf="@+id/slideBar"android:layout_below="@+id/rl_search"android:background="@color/grey" /><com.kuyu.kuyucontact.ui.view.SlideIndexBarandroid:id="@+id/slideBar"android:layout_width="30dp"android:layout_below="@+id/rl_search"android:layout_height="wrap_content"android:layout_alignParentRight="true" /></RelativeLayout>
反之,要是想有光标变把属性设为false

实现键盘自动弹出

方法一:

EditText  editText.setFocusable(true);  editText.setFocusableInTouchMode(true);  editText.requestFocus();  MethodManager inputManager =  (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);  inputManager.showSoftInput(editText, 0);  

方法二:

使用:android:windowSoftInputMode属性

activity主窗口与软键盘的交互模式,可以用来避免输入法面板遮挡问题,Android1.5后的一个新特性。

这个属性能影响两件事情:

【一】当有焦点产生时,软键盘是隐藏还是显示

【二】是否减少活动主窗口大小以便腾出空间放软键盘

它的设置必须是下面列表中的一个值,或一个state…”值加一个adjust…”值的组合。在任一组设置多个值——多个state…”values,例如&mdash有未定义的结果。各个值之间用|分开。例如:<activity android:windowSoftInputMode="stateVisible|adjustResize". . . >

在这设置的值("stateUnspecified""adjustUnspecified"以外)将覆盖在主题中设置的值


各值的含义:

【A】stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置

【B】stateUnchanged:当这个activity出现时,软键盘将一直保持在上一个activity里的状态,无论是隐藏还是显示

【C】stateHidden:用户选择activity时,软键盘总是被隐藏

【D】stateAlwaysHidden:当该Activity主窗口获取焦点时,软键盘也总是被隐藏的

【E】stateVisible:软键盘通常是可见的

【F】stateAlwaysVisible:用户选择activity时,软键盘总是显示的状态

【G】adjustUnspecified:默认设置,通常由系统自行决定是隐藏还是显示

【H】adjustResize:该Activity总是调整屏幕的大小以便留出软键盘的空间

【I】adjustPan:当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分



我在我的项目的用的stateVisible属性
在AndroidManifest.xml里面添加




更多相关文章

  1. Android开发设置Activity全屏与不全屏的方法
  2. 简单的Android(安卓)UI组件使用
  3. 解决TextView中MaxLines与ellipsize=end问题
  4. Android(安卓)TabHost布局
  5. Android(安卓)沉浸式状态栏完美解决方案
  6. 关于那些Android中不常用的设置属性
  7. 横屏和竖屏切换界面不刷新
  8. Android(安卓)Property System | Android属性系统
  9. TextView 属性

随机推荐

  1. android获取手机的所有通讯录的号码和sim
  2. android 开发,用一行代码操作只使用一次
  3. android Dialog实例
  4. Android里边如何使用二级列表
  5. Android 字体设置
  6. hudson/android emulator 无法启动
  7. Android中Fragment生命周期
  8. android studio实时预览报错
  9. android 使用fastjson解析json数据
  10. cpp通过Message掉java