【问题标题】:EditText with "constants"带有“常量”的 EditText
【发布时间】:2015-07-19 10:38:10
【问题描述】:

我想自定义一个 EditText,它应该具有如下图所示的“常量”,以便获得分钟和秒。 (号码界面无关)。

【问题讨论】:

  • 目前还没有,因为我不知道如何在代码中自定义 EditText
  • 这很简单,只需在此处发布您的观点,您实际上想要做什么......
  • Android 不支持蒙版编辑文本视图,但有可用的外部类可以修改默认行为..
  • 我在这里发帖是我对此的回答
  • amitsharma 我不明白你的意思..我只想要一个 EditText 应该在图片中看起来像这样

标签: android time android-edittext customization


【解决方案1】:

通过此代码尝试此代码在这里我已通过此代码尝试。此代码正在运行。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:orientation="vertical">  
<EditText 
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_marginTop="50dp" 
    android:textColor="#000000" 
    android:background="#CCCCCC"
    /> 
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="horizontal"
    >
<Button
    android:id="@+id/btn0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0" />

<Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1" />

<Button
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="2" />
</LinearLayout>
 <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    >
<Button
    android:id="@+id/btn3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="3" />

<Button
    android:id="@+id/btn4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="4" />

<Button
    android:id="@+id/btn5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="5" />
</LinearLayout>
 <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    >
<Button
    android:id="@+id/btn6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="6" />

<Button
    android:id="@+id/btn7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="7" />

<Button
    android:id="@+id/btn8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="8" />
</LinearLayout>

这里显示的是下面的图片

【讨论】:

  • 对不起,但正如我所说的数字界面无关紧要;我只想将上面的行作为 EditText
  • 只需在edittext之后添加textview,高度为2 dp,颜色为黑色或您想要的颜色..
【解决方案2】:

首先,我在您发布的屏幕上看不到 EditText,这是在单击数字时会更新的纯 TextView。

无论如何,您可以使用多个 TextView/EditText,这样您也可以轻松更改它们的格式,或者您可以自己以编程方式更改格式。如果您想拥有一个接受参数的字符串资源,请参阅here 了解如何执行此操作。

【讨论】:

  • 但是我想要一个动态的 EditText,当你输入一些数字时,应该跳过其中的“常量”。所以它应该在开头看起来像“0m00s”,当你输入例如第一个 1,然后是 2,然后是 0 它应该看起来像“1m20s”。
  • 您应该查看 EditText 实际上是什么。这不是 EditText。你想要一个简单的 TextView。通过单击数字(按钮),您将根据需要更改 TextView 的文本。您可以通过根据旧值和按下的新值重新计算文本来做到这一点,或者保留一个包含输入数字的列表,以便您每次都可以从该列表中创建文本。
  • 如果你真的想要一个 EditText 并且只是想在输入时保持一些格式,请考虑实现一个 TextWatcher:stackoverflow.com/questions/18305520/…
猜你喜欢
  • 2012-04-22
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
  • 2011-10-03
  • 1970-01-01
  • 2011-04-25
  • 2014-01-13
  • 2016-12-11
相关资源
最近更新 更多