动态限制EditText的最大长度。

问题描述 投票:0回答:1

问题是打字时的文字超出了EditText的界限!如何根据EditText的宽度(权重),动态限制maxLength?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    android:id="@+id/activity_1_cnstr_layout_main">

    <LinearLayout
        android:id="@+id/l_layout_1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">

        <EditText
            android:id="@+id/editText_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Text1" />

        <EditText
            android:id="@+id/editText_2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Text2" />
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
android android-edittext maxlength
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.