gpt4 book ai didi

android - 在白色背景上带有 float 标签的 TextInputLayout Android 中的可见性问题

转载 作者:行者123 更新时间:2023-11-29 01:05:31 25 4
gpt4 key购买 nike

我正在创建具有 textimputlayout float 标签的简单登录屏幕。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" />

屏幕截图是In this image the field of the edit text is not visible.

我已经搜索并尝试了很多编辑文本的可见性,但是当我将背景赋予 xml 文件时,就像它显示的任何颜色一样,我没有找到任何合适的理由。但在白色背景下它是不可见的。请指导我解决上述问题。

最佳答案

您可以使用主题更改 float 标签的颜色,只需在您的 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>

关于android - 在白色背景上带有 float 标签的 TextInputLayout Android 中的可见性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47550093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com