【问题标题】:customizing my android edittext自定义我的 android 编辑文本
【发布时间】:2023-03-23 08:45:01
【问题描述】:

我想自定义我的 android 编辑文本,以便:

  1. edittext 末尾会有一个按钮
  2. 按钮在下划线范围内
  3. 输入的文本不会超过按钮
  4. edittext 开头的省略号

所以它看起来像这样,例如:

.̲.̲e̲d̲i̲t̲t̲e̲x̲t̲ ̲[̲b̲u̲t̲t̲o̲n̲]̲̲

而不是将文本放在按钮下方

【问题讨论】:

  • 您所要求的大部分内容只是涉及在特定布局中添加一个按钮,可能是水平的。你试过了吗?
  • 我尝试以这种方式构建线性布局(方向:水平),下划线部分(单击edittext时带有一些动画)将停在按钮的左侧;我想要的是让下划线也覆盖按钮

标签: android android-edittext android-button


【解决方案1】:

尝试使用 EditText android:drawableRight="@drawable/ic_calender" 在 Edittext set max line property android:maxLines="1" 中设置图标

        <EditText
        android:layout_width="match_parent"
        android:drawableRight="@drawable/ic_calender"
        android:ellipsize="start"
        android:maxLines="1"
        android:text="tjhdshdhsdhjdhd"
        android:layout_height="wrap_content" />

你也可以像这样设置点击监听器

 editText.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        if(event.getAction() == MotionEvent.ACTION_UP) {
            if(event.getRawX() >= (editComment.getRight() - editComment.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                // your action here

             return true;
            }
        }
        return false;
    }
});

【讨论】:

    猜你喜欢
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多