Плавающий намек в EditText [дубликат]

Сравнение строк в фразе WHERE не чувствительно к регистру. Вы можете попытаться сравнить, используя

WHERE `colname` = 'keyword'

или

WHERE `colname` = 'KeyWord'

, и вы получите тот же результат. Это поведение по умолчанию MySQL.

Если вы хотите, чтобы сравнение было чувствительным к регистру, вы могли бы добавить COLLATE так же, как это:

WHERE `colname` COLLATE latin1_general_cs = 'KeyWord'

Тот SQL дал бы другой результат с этим: WHERE colname COLLATE latin1_general_cs = 'keyword'

latin1_general_cs является общей или стандартной настройкой в ​​большинстве баз данных.

3
задан Ferdous Ahamed 10 July 2017 в 13:05
поделиться

1 ответ

Вот обходной путь:

1. Создайте структуру layout, как показано ниже:

activity_test.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp"
    android:background="@android:color/white">

    <!-- Username -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:layout_width="match_parent"
            android:layout_height="52dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/bg_rounded_input_field" />

        <TextView
            android:id="@+id/text_dummy_hint_username"
            android:layout_width="wrap_content"
            android:layout_height="2dp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="16dp"
            android:paddingLeft="4dp"
            android:paddingRight="4dp"
            android:text="Username"
            android:textSize="16sp"
            android:background="@android:color/white"
            android:visibility="invisible"/>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:hint="Username"
            android:textColorHint="@android:color/black"
            app:hintTextAppearance="@style/HintTextStyle">

            <EditText
                android:id="@+id/edit_username"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text|textCapWords"
                android:maxLines="1"
                android:backgroundTint="@android:color/transparent"/>
        </android.support.design.widget.TextInputLayout>
    </RelativeLayout>

    <!-- Password -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp">

        <View
            android:layout_width="match_parent"
            android:layout_height="52dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/bg_rounded_input_field" />

        <TextView
            android:id="@+id/text_dummy_hint_password"
            android:layout_width="wrap_content"
            android:layout_height="2dp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="16dp"
            android:paddingLeft="4dp"
            android:paddingRight="4dp"
            android:text="Password"
            android:textSize="16sp"
            android:background="@android:color/white"
            android:visibility="invisible"/>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:hint="Password"
            android:textColorHint="@android:color/black"
            app:hintTextAppearance="@style/HintTextStyle">

            <EditText
                android:id="@+id/edit_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:maxLines="1"
                android:backgroundTint="@android:color/transparent"/>
        </android.support.design.widget.TextInputLayout>
    </RelativeLayout>
</LinearLayout>

2. Используйте ниже для рисования bg_rounded_input_field.xml для закругленных углов.

res / drawable / bg_rounded_input_field.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <stroke
        android:color="@android:color/black"
        android:width="2dp">
    </stroke>

    <corners
        android:radius="8dp">
    </corners>

</shape>

3. Используйте ниже HintTextStyle до TextInputLayout, добавив атрибут app:hintTextAppearance="@style/HintTextStyle".

res / values ​​/ styles.xml

<style name="HintTextStyle" parent="TextAppearance.Design.Hint">
    <item name="android:textSize">16sp</item>
</style>

4. Наконец, в вашем Activity только show/hide TextView text_dummy_hint_username и text_dummy_hint_password в течение focus изменится.

FYI, я использовал Handler с задержкой 100 millis, чтобы показать фиктивные подсказки TextView для синхронизации с текстом подсказки TextInputLayout animation.

TestActivity.java

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class TestActivity extends AppCompatActivity {

    TextView textDummyHintUsername;
    TextView textDummyHintPassword;
    EditText editUsername;
    EditText editPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        textDummyHintUsername = (TextView) findViewById(R.id.text_dummy_hint_username);
        textDummyHintPassword = (TextView) findViewById(R.id.text_dummy_hint_password);
        editUsername = (EditText) findViewById(R.id.edit_username);
        editPassword = (EditText) findViewById(R.id.edit_password);

        // Username
        editUsername.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {

                if (hasFocus) {
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            // Show white background behind floating label
                            textDummyHintUsername.setVisibility(View.VISIBLE);
                        }
                    }, 100);
                } else {
                    // Required to show/hide white background behind floating label during focus change
                    if (editUsername.getText().length() > 0)
                        textDummyHintUsername.setVisibility(View.VISIBLE);
                    else
                        textDummyHintUsername.setVisibility(View.INVISIBLE);
                }
            }
        });

        // Password
        editPassword.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {

                if (hasFocus) {
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            // Show white background behind floating label
                            textDummyHintPassword.setVisibility(View.VISIBLE);
                        }
                    }, 100);
                } else {
                    // Required to show/hide white background behind floating label during focus change
                    if (editPassword.getText().length() > 0)
                        textDummyHintPassword.setVisibility(View.VISIBLE);
                    else
                        textDummyHintPassword.setVisibility(View.INVISIBLE);
                }
            }
        });
    }
}

OUTPUT:

Надеюсь, это поможет ~

11
ответ дан Ferdous Ahamed 16 August 2018 в 05:08
поделиться
Другие вопросы по тегам:

Похожие вопросы: