Buna benzeyen bir editText nasıl oluşturabilirim?Android EditText farklı yüzer etiket ve yer tutucu ile
cevap
Sen olarak aşağıda düzen xml dosyasına aşağıda kullanabilirsiniz. görünüm odaklı değilken TextInputEditText
den android:hint="Placeholder"
TextInputLayout
den android:hint="Label"
ile aynı anda görünür olduğunu
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:textColor="@color/wallet_holo_blue_light" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="@+id/editText2"
android:hint="Placeholder" />
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Label">
<android.support.design.widget.TextInputEditText
android:hint="Placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
dikkat edin. Bu etiketi göstermek ve gizlemek için java kodunuza fazladan kontrol edebilirsiniz. Veya TextInputLayout
'dan android:hint="Placeholder"
'u bırakın.
TextInputLayout
için
android:theme="@style/TextLabel
kullanarak tema ayarlamak gerekir ve renk vurgusu var ayarlayın. Eğer EDITTEXT odağı daha sonra textinputlayout kullanırsanız
<style name="TextLabel" parent="TextAppearance.AppCompat.Light">
<item name="colorAccent">@color/yourColor</item>
</style>
, herhangi yer tutucu alamadım.
Düzen:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/username_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
Sen EDITTEXT bir odak değişikliği dinleyici belirlemek zorunda.
Java:
usernameTxt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
usernameTxt.setHint("Label");
} else {
usernameTxt.setHint("Placeholder");
}
}
});
Sen TextInputLayout
ve EditText
kullanarak bunu yapabilirsiniz. TextInputLayout
için android:hint="Label"
her zaman ipuçları Label
göstermek için
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Label">
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
1. Add özellik:
İşte XML olduğunu.
2.
ProgramlıEditText
ipuçları EditText
odaklı olsun sadece Placeholder
ayarlayın. Faaliyetinizdeki hatları aşağıda ekleyin:
.........
.................
final EditText editText = (EditText) findViewById(R.id.edit_text);
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
editText.setHint("Placeholder");
} else {
editText.setHint("");
}
}
});
.........
..................
ÇIKIŞ:
Umut bu yardımcı olacaktır ~
Sen KOTLIN içinde (kod aşağıdaki kullanabilirsiniz). 200 ms gecikme sonrasında (çakışan ipucu ve yer tutucuyu önlemek için) yer tutucu gösterecektir.
class PlaceholderEditText : TextInputEditText {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
private val placeholder = hint
init {
hint = ""
onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
postDelayed({ hint = placeholder }, 200)
} else {
hint = ""
}
}
}
}
ve sonra düzen xml sınıfında
:<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ALWAYS VISIBLE LABEL">
<com.myapp.widget.PlaceholderEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="DISAPPEARING PLACEHOLDER" />
</android.support.design.widget.TextInputLayout>
- 1. Android Glide yer tutucu büyüklüğü
- 2. HTML5 yer tutucu gibi
- 3. Merkez hizalama yer tutucu sorunu android
- 4. iframe Yer Tutucu Görüntü
- 5. fontawesome kullanıcı yer tutucu
- 6. Yer Tutucu Metin Biçimlendirme
- 7. Codenameone FontImage bir yer tutucu ile
- 8. Yer tutucu rengini css3 ile nasıl değiştirebilirim?
- 9. Bir asp ile Kentico dönüşümü: yer tutucu
- 10. :: - webkit-giriş-yer tutucu çalışmaz
- 11. Animasyonu Yer Tutucu Olarak Yazma
- 12. Tip cast std :: yer tutucu
- 13. Javascript dosyalarındaki Yeoman yer tutucu
- 14. CSS LESS Yer Tutucu Karıştırıcı
- 15. Textarea için yer tutucu? (ExtJS)
- 16. Yerel tutuculardan yer tutucu metinleri hariç
- 17. Yer tutucu metni gösterilmiyor (pyside/pyqt)
- 18. Simge ile Android Özel EditText
- 19. Yukarı ve aşağı oku ve yer tutucu metnini nasıl gizleyebilirim?
- 20. HTML5 Yer tutucu özellik algılama sorunları
- 21. Kordon Dizgisi Değiştirme - yer tutucu yok
- 22. Yay özellikleri (özellik-yer tutucu) otomatik kablolama
- 23. Android Yüzer Düğmesi gösterilmiyor
- 24. JPQL karşılaştırma operatörleri için yer tutucu
- 25. Android - Farklı yapı tipleri
- 26. Android: EditText - çoklu satırlar ve android: inputType
- 27. React JSX: Yer tutucu özniteliğine nasıl ayarlanır?
- 28. Android: EditText
- 29. bu satır numarası yer tutucu excel formülü
- 30. Tinerde Girişe nasıl yer tutucu eklenir?
etiket tutmak ve odaklanmamış halde ekran görüntüsü gibi yer tutucu bir yolu var mı? –
Evet, mümkün. Ebeveyn/kapsayıcı düzenine android: focusableInTouchMode = "true" 'kullanın. – FAT