美文网首页
Android开发的小技巧

Android开发的小技巧

作者: 傲娇的狗蛋 | 来源:发表于2019-04-17 10:42 被阅读0次

前言

平时开发中经常遇到的小的问题,这里记录一下。

EditText禁止自动弹出软键盘的方法

在包含EditText的父布局中添加android:focusable="true"android:focusableInTouchMode="true"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     android:focusable="true"
     android:focusableInTouchMode="true"
   >
   <EditText
       android:id="@+id/edit"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:inputType="text"
       android:maxLines="1"
       />
</LinearLayout>

ScrollView默认位置不是最顶部解决方案

跟EditText一样,在父元素的属性这两行即可android:focusable="true"android:focusableInTouchMode="true"

进入页面让EditText自动弹出键盘

  /**
     * 打开软键盘
     *
     * @param view
     */
    public static void openKeybord(final View view) {
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                ((InputMethodManager) view.getContext().getSystemService(
                        Context.INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
            }
        },100);

    }

目前测试此方法在页面初始化调用不能自动打开键盘,但在点击事件中可以打开

相关文章

  • Android开发小技巧

    1.Touch处理 MotionEventCompat.getActionMasked(ev)等价于event.g...

  • android开发小技巧

    1.无干扰模式(Distraction Free Mode) 您可以依次点击: View → Enter Dist...

  • Android 开发小技巧

    Android 开发小技巧 前言 做了许久的开发,常常有些小细节会打动到我,希望这篇文章可以记录这些分享给大家 布...

  • Android 开发小技巧

    1、5.0以上点击水波纹效果 在想要实现效果的布局或控件中加入: 2、5.0以上使用4.0的时间日期选择控件样式 ...

  • Android开发小技巧

    List的倒序Collections类是一个java的工具类,在java.util包下面.提供了集合的复制和倒序,...

  • Android 开发小技巧

    昨天看郭霖的书,发现两个很实用的开发技巧,哈哈哈,很高兴今天记得,写下来! 1 方便调试 我们开发时项目写的比较大...

  • Android开发小技巧

    在Android Studio项目中设置文件夹显示层级效果. 如果项目有不同的包名的时候,需要分层次文件夹结构点击...

  • Android开发的小技巧

    前言 平时开发中经常遇到的小的问题,这里记录一下。 EditText禁止自动弹出软键盘的方法 在包含EditTex...

  • Flutter开发小技巧

    这篇文章会持续更新,记录开发中遇到的小技巧 1.断点调试小技巧 方式一: Android studio 小虫子de...

  • Android开发中那些常用的Gradle配置

    在Android开发中除了掌握开发APP的技能,还有许多其他的小技巧都能提高我们的开发效率,比如git操作,she...

网友评论

      本文标题:Android开发的小技巧

      本文链接:https://www.haomeiwen.com/subject/apegwqtx.html