编辑文本提示未出现在更高版本的SDK上 [英] Edit Text hints not appearing on later version SDK

查看:58
本文介绍了编辑文本提示未出现在更高版本的SDK上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是针对SDK 1.5 3.0编写的,但是在更高版本上运行时,提示未出现在EditText视图中.有什么建议吗? 干杯, 里克

My app has been written for SDK 1.5 3.0 but when it is running on later versions the hints are not appearing in the EditText views. Any suggestions please? Cheers, Rick

这是xml布局代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/scrollView1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#123456"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/warningTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:text="@string/warningTV"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/csTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/csTitle"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/csET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:textColor="#123456"
        android:gravity="center_horizontal"
        android:hint="@string/csET" 
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/diaTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/diaTitle"
        android:textColor="#FFFFFF"
        android:textSize="20dp" />

    <EditText
        android:id="@+id/diaET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:hint="@string/diaET"
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/feedTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/feedTitle"
        android:textColor="#FFFFFF"
        android:textSize="20dp" />

    <EditText
        android:id="@+id/feedET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:hint="@string/feedET"
        android:inputType="numberDecimal" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/numTeeth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/numTeeth"
        android:textColor="#FFFFFF"
        android:textSize="20dp" />

    <EditText
        android:id="@+id/teethET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:hint="@string/teethET"
        android:inputType="number" />

    <Button
        android:id="@+id/calcButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/calcButton"
        android:textColor="#123456"
        android:textSize="20sp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/resetButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/resetButton"
        android:textColor="#123456"
        android:textSize="20sp"
        android:textStyle="bold" />
</LinearLayout>

</ScrollView>

您会注意到,在EditText中,我链接到提示的字符串值.奇怪的是,这些提示仅出现在早期的SDK中,而没有出现在以后的SDK中.在仿真器和实际设备中都会发生这种情况.

You will notice that in the EditText I link to a string value for the hint. Strangely the hints only appear in early SDK but not later ones. This occurs in both the emulator and actual devices.

推荐答案

我刚才也回答了一个非常相似的问题:

I just answered a very similar question to this as well:

EditText提示未显示

在这里,我认为您的问题已经解决了,在元素"EditText"中添加某些布局,例如"android:gravity ="center_horizo​​ntal",可能会导致您的问题:

Here I believe your question has already been solved before, adding certain layouts to the element "EditText" such as "android:gravity="center_horizontal" may cause your problem:

如何在使用inputType ="numberDecimal的EditText中添加提示"?

尝试将其删除,然后将其包装在使用"android:gravity ="center_horizo​​ntal"的布局中,然后将"EditText"元素放入其中.

Try removing that and wrap it in a layout that uses "android:gravity="center_horizontal" and put the "EditText" element inside.

StackOverflow上的工作示例:

Working example on StackOverflow:

行不不能在Android版式中正确呈现.按钮似乎是问题所在

在此处进行快速Google搜索是一些使人们能够使用它的示例:

Doing a quick Google search here are some examples where people have gotten it to work:

Android教程系列第2部分–计算器应用

单元测试与-junit-testing-framework

Android 4-应用 抵押贷款计算器

Android 4 - Apps Mortagage Calculator

我使用Android 1.5来确保所有手机和平板电脑都可以运行我创建的任何应用程序.祝你好运!

I use Android 1.5 in order to make sure that all phones and tablets can run any application I create. Goodluck!

这篇关于编辑文本提示未出现在更高版本的SDK上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆