zoukankan      html  css  js  c++  java
  • <Android 基础(二十二)> EditText 无法显示完全以及尝鲜Android N

    前言

    最近将Android Studio更新到了2.2 ,模拟器的Android版本也来到了最新的Nougat。很令人兴奋的一件事情呢! 对, 我就是这么没出息。文章结尾来几张图。

    问题

    最近遇到一个问题,EditText只读的情况下,在ScrollView下无法滚动,原因应该就是滑动事件优先被ScrollView消耗,导致EditText并没有收到滚动事件,导致如是问题

    解决办法:

    EditText editText = (EditText) findViewById(R.id.EditText01);
    EtOne.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (v.getId() == R.id.comment1) {
                v.getParent().requestDisallowInterceptTouchEvent(true);//组织父节点消耗滑动事件
                    switch (event.getAction() & MotionEvent.ACTION_MASK) {
                        case MotionEvent.ACTION_UP:
                            v.getParent().requestDisallowInterceptTouchEvent(false);
                            break;
                    }
                }
            return false;
        }
    });

    这种情况下,EditText应该是可编辑状态,但是我们的要求是只读,也就是无法编辑,这种情况下,如果用户点击到了文本区域内,会弹出输入法,用户便可以直接输入,这个问题如何解决

    解决办法:

    • 阻止输入法弹出
    editText = (EditText) findViewById(R.id.editText);
    editText.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            int inType = editText.getInputType(); // backup the input type
            editText.setInputType(InputType.TYPE_NULL); // disable soft input
            editText.onTouchEvent(event); // call native handler
            editText.setInputType(inType); // restore input type
            editText.setSelection(editText.getText().length());
            return true;
        }
    });
    • 阻止输入法弹出
    edittext.setKeyListener(null);

    Sets the key listener to be used with this TextView. This can be null
    to disallow user input.
    Note that this method has significant and
    subtle interactions with soft keyboards and other input method:
    see {@link KeyListener#getInputType() KeyListener.getContentType()}
    for important details. Calling this method will replace the current
    content type of the text view with the content type returned by the
    key listener.

    Android Nougat模拟器

    Android Studio2.2上的模拟器速度还是比较快的。
    这里写图片描述这里写图片描述
    这里写图片描述
    这里写图片描述

    Google原生的内容依然是那么的干净,清晰,功能强大。模拟器的功能也是比较健全的。
    N版本具体更新内容,请关注官网:
    https://developer.android.com/about/versions/nougat/android-7.0.html

    Android Studio 2.2

    正题界面风格没有很大的变化,图标有变化,给我印象最深的是UI编辑器

    这里写图片描述

    编辑器中多了一个视图,上方多了一些按钮,右侧的属性可能更丰富了吧,之前我都是全部手写的,真是浪费好的开发工具。具体的更新内容请关注官网:
    https://developer.android.com/studio/releases/index.html

  • 相关阅读:
    软件构造期末复习考点总结
    设计模式
    怎么写测试策略
    FreeRTOS任务创建、启动调度器、任务切换的过程分析——基于ARM-CotexM3
    Altium Designer 创建集成封装库(.IntLib文件)的方法
    Altium Designer多通道设计的原理与应用实例
    我的编程命名风格
    计算机网络学习笔记
    基于串口通信做my_printf时遇到的坑儿
    git常用命令
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6467168.html
Copyright © 2011-2022 走看看