白色背景上带有浮动标签的 TextInputLayout Android 中的可见性问题

2023-12-22

我正在创建具有 textinputlayout 浮动标签的简单登录屏幕。 下面给出了 java 文件和 xml。

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send_cryptocurrency);
        // get the reference of View's
        emailTextInputLayout = (TextInputLayout) findViewById(R.id.emailTextInputLayout);
        passwordTextInputLayout = (TextInputLayout) findViewById(R.id.passwordTextInputLayout);
        email = (EditText) findViewById(R.id.emailEditText);
        password = (EditText) findViewById(R.id.passwordEditText);
        signIn = (Button) findViewById(R.id.signInButton);
// perform click event on sign In Button
        signIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (validate(email, emailTextInputLayout) && validate(password, passwordTextInputLayout)) {
//  display a Thank You message
                    Toast.makeText(getApplicationContext(), "Thank You", Toast.LENGTH_LONG).show();

                }
            }
        });
    }

    // validate fields
    private boolean validate(EditText editText, TextInputLayout textInputLayout) {
        if (editText.getText().toString().trim().length() > 0) {
            return true;
        }
        editText.requestFocus(); // set focus on fields
        textInputLayout.setError("Please Fill This.!!!"); // set error message
        return false;
    }

和 xml 文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android.support.design="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<!-- first TextInputLayout -->
<android.support.design.widget.TextInputLayout
    android:id="@+id/emailTextInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android.support.design:counterMaxLength="3">

    <EditText
        android:id="@+id/emailEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Email Id" />
</android.support.design.widget.TextInputLayout>
<!-- first TextInputLayout -->

<android.support.design.widget.TextInputLayout
    android:id="@+id/passwordTextInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Password">

    <EditText
        android:id="@+id/passwordEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<!-- sign In Button -->
<Button
    android:id="@+id/signInButton"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="20dp"
    android:text="Sign In"
    android:textColor="#000000"
    android:textSize="20sp"
    android:textStyle="bold" />

and the screen shot isIn this image the field of the edit text is not visible.

我已经搜索并尝试了很多编辑文本可见性,但当我为 xml 文件提供背景(如它显示的任何颜色)时,没有找到任何适当的原因。但在白色背景下它是不可见的。请指导我解决上述问题。


您可以使用主题更改浮动标签的颜色,只需在 styles.xml 中添加以下代码

<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/red</item>
    <item name="android:textSize">14sp</item>
</style>

然后将此主题应用到您的 TextInputLayout

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColorHint="@color/gray"
    app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">

    <android.support.v7.widget.AppCompatEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint" />
</android.support.design.widget.TextInputLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

白色背景上带有浮动标签的 TextInputLayout Android 中的可见性问题 的相关文章

  • 如何在android中使用kso​​ap2库解析复杂的响应

    大家好 我正在使用 Ksoap2 库解析以下类型的响应 但没有成功获得结果 我的请求如下
  • 如何从我的班级访问活动 UI?

    我有一个活动创建我的类的对象实例 file MyActivity java public class MyActivity extends Activity TextView myView TextView findViewById R i
  • 单击应用程序的启动图标时会发生什么?

    单击应用程序的启动图标时会发生什么 是否总是发送新意图 或者结果有时与从最近的任务恢复任务相同 如果发送意图 它何时被发送到新活动实例的 onCreate 方法以及何时通过现有活动的 onNewIntent 进行路由 假设意图通过任务中现有
  • layout_constrainedWidth 无法正常工作

    我的 ConstraintLayout 中有 EditText 和 TextView TextView显示EditText的内容 输入时 我需要 EditText 展开直到屏幕中间 而 TextView 跟随它并填充后半部分 我将指导方针设
  • Android:每次单击导航抽屉项时创建一个新片段更好,还是加载以前创建的片段更好?

    我正在为 Android 实现标准导航抽屉模式 用户可以从抽屉中导航到大约 10 个片段 目前 每次单击不同的导航抽屉项目时 我都会创建一个新的片段 如下所示 When a new navigation item at index is c
  • Android 通知 - 显示完整消息

    我的 Android 应用程序必须能够向一大群人发送简短的警报 执行此操作的明显位置是在通知中心 完整的通知毫无问题地显示在股票代码中 但在通知中心 用户只能看到前几个单词 然后是省略号 通知并不长 最多也就10 15个字 如何使文本自动换
  • 无法实例化接收器 com.parse.GcmBroadcastReceiver

    我正在编写一个使用 GCM 通知和解析推送的离子应用程序 这个应用程序正在使用这些插件 com ionic keyboard 1 0 3 Keyboard com phonegap plugins PushPlugin 2 4 0 Push
  • 自定义视图的Ondraw无限循环android

    我的自定义视图的 OnDraw 函数被无限调用并且正在循环 可能的原因是什么 这是我的自定义视图 public class Balls extends View private static final String TAG BallsVi
  • 在 Marshmallow 中获取蓝牙本地 mac 地址

    在 Marshmallow 之前 我的应用程序将通过以下方式获取其设备 MAC 地址BluetoothAdapter getDefaultAdapter getAddress 现在 随着 Marshmallow Android 的回归02
  • Android NDK C++“wstring”支持

    我有用 C 编写的源代码 lib 现在我想在 Android NDK 项目 NDK 6 中编译并使用相同的源代码 lib 我能够编译大多数 C 文件 除了基于 std wstring 的功能 在 Application mk 中 当我指定时
  • Android Realm.io:行/对象不再有效

    这是我的删除功能 它确实找到了workday1 object public static void delete Context context Workday workday Realm realm getRealm context re
  • 检查应用程序是否首次运行[重复]

    这个问题在这里已经有答案了 我是 Android 开发新手 我想根据应用程序安装后首次运行来设置一些应用程序的属性 有什么方法可以发现应用程序是第一次运行 然后设置其首次运行属性吗 下面是一个使用的例子SharedPreferences实现
  • 从代码动态更改多个文本视图的大小(没有“磁盘上”xml 主题)?

    我有 10 个文本视图在我的代码中 我想更改所有代码的字体大小 在我的布局中我使用了 style定义通用属性 但是我不知道一旦布局出现在屏幕上如何从代码中更改它们 我不想做的是更新 AND 对象 但只写在一处 我知道我可以使用应用主题但这假
  • Facebook Android 意图

    我对这个意图有疑问 这个意图是发送文本类型的消息 一切正常 电子邮件 短信 推特以及手机上的任何内容 但唯一有问题的是facebook 它会尝试以链接而不是文本的形式发布 Intent s new Intent android conten
  • Webview 电子邮件链接 (mailto)

    我有一个视图并查看该网站有用于发送电子邮件的 malito 代码 当我打开链接时 会出现错误 我希望当我打开链接时打开 Gmail 应用程序或其他电子邮件应用程序 感谢所有帮助者 public class teacher extends A
  • 如何在kotlin中使用Coroutine每秒调用一个函数

    我刚刚创建了一个应用程序 其中我的函数 getdata 每秒调用一次以从服务器获取新数据 而 updateui 函数将更新 UI 中的视图 我在我的应用程序中不使用任何异步任务或协程 我想这样做 请告诉我我怎样才能做到这一点 这是我的代码
  • Phonegap facebook 插件:android 的各种问题

    我正在尝试将 Phonegap 3 1 与 Phonegap facebook plugin 集成 以使我的应用程序能够使用 facebook 登录 https github com phonegap phonegap facebook p
  • 读/写带有特殊字符的.txt文件

    I open Notepad Windows 并写 Some lines with special characters Special 并前往另存为 someFile txt 与Encoding set to UTF 8 在Java中我有
  • 如何将QR码中的3个方块替换为圆圈以使用Paint android使用zxing自定义QR码?

    我用它作为自定义的参考 从方形到圆形使用zxing生成的QR码它是在java中所以我尝试将它转换为在android中使用 使用 zxing 生成具有自定义点形状的 QR 码 https stackoverflow com questions
  • 如何检测用户是否禁用 GPS(Android - Play 服务)

    我使用 gms location LocationListener Google Play 服务 来获取用户的位置 它工作正常 但我想检测用户何时禁用或启用他 她的 GPS 就像这张照片一样 当我打开 关闭位置时 不会调用任何方法 当我切换

随机推荐