简体   繁体   English

用于 EditText 的具有数字和基本数学运算的键盘

[英]keyboard with numeric and basic math operations for an EditText

How I can have this keyboard我怎么能有这个键盘

在此处输入图像描述

for an EditText?对于 EditText?

I tried with InputType but I could not have this keyboard.我尝试使用 InputType,但我无法使用此键盘。

I have created this example that shows the answers are not solving the problem:我创建了这个例子,显示答案没有解决问题:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent">

        <!--number-->
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hint"
            android:inputType="number" />
    </com.google.android.material.textfield.TextInputLayout>

    <!--numberDecimal|numberSigned-->
    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberDecimal|numberSigned"
        android:digits="0123456789.+-*/%()"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout" />

    <!--numberPassword-->
    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberPassword"
        app:layout_constraintTop_toBottomOf="@+id/editText" />

</androidx.constraintlayout.widget.ConstraintLayout>

the resulted keyboards for the first two input types are same and they are like:前两种输入类型的结果键盘是相同的,它们就像: 在此处输入图像描述

and the last one is like:最后一个是这样的:

在此处输入图像描述

You can use this for displaying only numbers:您可以使用它来仅显示数字:

<EditText
        android:id="@+id/editTextNumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number" />

Or use this for displaying numbers when you use the EditText for Passwords:或者在使用 EditText 密码时使用它来显示数字:

<EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberPassword" />

Please also understand that mostly every phone has another keyboard design, so you may not get the exact keyboard you mentioned in you picture另请理解,大多数手机都有另一种键盘设计,因此您可能无法获得您在图片中提到的确切键盘

use this用这个

<EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number" />

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

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