zoukankan      html  css  js  c++  java
  • Android点击EditText文本框之外任何地方隐藏键盘的解决办法

    通过给当前界面布局文件的父layout设置点击事件(相当于给整个Activity设置点击事件),在事件里进行键盘隐藏


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/traceroute_rootview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:clickable="true"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    </LinearLayout>
    加上id和clickable=true
    然后在onCreate里,添加onClick事件的监听:


    findViewById(R.id.traceroute_rootview).setOnClickListener(this);
    在onClick中:

    @Override
    public void onClick(View v) {
    switch (v.getId()) {
    case R.id.traceroute_rootview:
    InputMethodManager imm = (InputMethodManager)
    getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    break;
    }

    }

    这样就可以完美的解决了输入框外的隐藏效果,对于布局不是特别复杂或是其它触摸事件少的情况下可以使用。

  • 相关阅读:
    网线接线分类
    MongoDB修改用户密码
    win10计算器和商店英文改中文
    电脑微信双开
    ajax
    get和post的区别
    javascript中各种继承方式的优缺点
    原型
    高阶函数的封装
    深浅拷贝
  • 原文地址:https://www.cnblogs.com/tc310/p/9779092.html
Copyright © 2011-2022 走看看