发布于 2017-09-22 00:15:31 | 120 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android 开发实现EditText 光标居右显示的相关资料,需要的朋友可以参考下

 Android 开发实现EditText 光标居右显示

前言:

有些时候肯定会遇到这种奇葩的需求,光标要靠右显示,因为Android里面光标默认是靠左显示的,那怎么实现呢,肯定有办法的,这里提供一种实现方式,看布局


 <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
      android:id="@+id/tv"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginRight="6dp"
      android:background="@null"
      android:gravity="right|center_vertical"
      android:text="请输入您想输入的" />

    <EditText
      android:id="@+id/et"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="right|center_vertical" />
  </FrameLayout>

看布局你就明白是什么意思 了吧,代码里面监听EditText输入,让TextView显示隐藏就行了。


 et.addTextChangedListener(new TextWatcher() {
      @Override
      public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
      }

      @Override
      public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        if (TextUtils.isEmpty(charSequence)) {
          tv.setVisibility(View.VISIBLE);
        } else {
          tv.setVisibility(View.GONE);
        }
      }

      @Override
      public void afterTextChanged(Editable editable) {
      }
    });

 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务