繁体   English   中英

蒙面的 EditText 不起作用 android 工作室

[英]Masked EditText is not working android studio

我想使用 Masked EditText 来编辑文本购物车号码,但我的代码是错误的,我不明白什么问题请帮助我

我的错误:

Caused by: android.view.InflateException: Binary XML file line #142: Binary XML file line #142: Error inflating class com.example.maskedlib.MaskedEditText Caused by: android.view.InflateException: Binary XML file line #142: Error inflating class com.example.maskedlib.MaskedEditText

我的代码 xml:

<com.example.maskedlib.MaskedEditText
            android:id="@+id/edt_cart_number"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentEnd="true"
            android:layout_marginStart="2dp"
            android:layout_marginEnd="-2dp"
            android:layout_toEndOf="@id/ibutton_mic"
            android:background="@null"
            app:mask="####-####-####-####"
            android:fontFamily="@font/iswebmedium"
            android:inputType="phone"
            android:hint="@string/txt_cart"
            android:textAlignment="center"
            android:textColorHint="@color/color_input_cart"
            android:textSize="15sp" />

这些链接上有2个不错的教程:

https://github.com/egslava/edittext-mask

https://medium.com/@diegoy_kuri/masks-in-android-edit-text-fields-33a2fd47f1af

您必须为掩码创建 class,因为属性“app:mask”不能像这样工作(有时像 android:fontFamily)。

希望这些教程能帮到你!

@加布里埃尔

我使用这个库,但我有错误

android.view.InflateException: Binary XML file line #142: Binary XML file line #142: Error inflating class br.com.sapereaude.maskedEditText.MaskedEditText

我的 xml 代码:

<br.com.sapereaude.maskedEditText.MaskedEditText
            android:id="@+id/edt_cart_number"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentEnd="true"
            android:layout_marginStart="2dp"
            android:layout_marginEnd="-2dp"
            android:layout_toEndOf="@id/ibutton_mic_cart_number"
            android:background="@null"
            android:fontFamily="@font/iswebmedium"
            android:hint="شماره کارت"
            android:inputType="phone"
            android:textAlignment="center"
            android:textColorHint="@color/color_input_cart"
            android:textSize="15sp"
            android:typeface="monospace"
            app:keep_hint="true"
            mask:allowed_chars="1234567890"
            mask:mask="####-####-####-####" />

我的活动代码:

edt_cart_number = findViewById(R.id.edt_cart_number); edt_cart_number.getRawText() String a = MaskedEditText edt_cart_number;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM