Wednesday, October 14, 2015

Beware EditText on API 21

Beware EditText on API 21 - Hallo sahabat Google Android Developer Tutorial, Pada Artikel yang anda baca kali ini dengan judul Beware EditText on API 21, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : Beware EditText on API 21
link : Beware EditText on API 21

Baca juga


Beware EditText on API 21

sourcehttp://blog.danlew.net/2015/09/09/dont-use-dynamic-versions-for-your-dependencies/

Beware EditText on API 21

Check out these two EditTexts. One is on an API 21 device, the other on an API 22 device.
See the difference? It's even more pronounced with "show layout bounds" enabled:
The height and vertical alignment of the EditTexts are different! This was caused by a change in the background of EditText between v21 and v22 (diff).
This change can cause sadness if your EditText is vertically aligned with otherViews, such as this case in Trello:
The text should be aligned with the icons, yet clearly it's not. The screenshot above is from 5.0; any other version of Android looks perfectly fine.
This problem crops up even if you're using AppCompat. AppCompat usually defers to the system material styles on v21+, which is the source of the problem.

Solution

Both solutions I've come up with use resource qualifiers to handle API 21 in a special manner.
One possibility is to import your own EditText background assets for API 21. Unless your app is filled with vertically-aligned EditTexts this seems like more effort than it's worth, since precision-targeting the background of EditTexts for just a single API version is tricky.
The hackier (but easier) solution is to just define different margins or paddings based on the API level. For example, I found that they're ~6dp off, so you end up with resources like this:
<!-- values/dimens.xml -->  
<dimen name="edit_text_spacing">6dp</dimen>

<!-- values-v21/dimens.xml -->
<dimen name="edit_text_spacing">0dp</dimen>

<!-- values-v22/dimens.xml -->
<dimen name="edit_text_spacing">6dp</dimen>
I'd be the first to admit it's ugly, but if there's only a handful of places you're fixing the problem, it's not so bad.


Demikianlah Artikel Beware EditText on API 21

Sekianlah artikel Beware EditText on API 21 kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel Beware EditText on API 21 dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2015/10/beware-edittext-on-api-21.html

Artikel Terkait

Beware EditText on API 21
4/ 5
Oleh

Berlangganan

Suka dengan artikel di atas? Silakan berlangganan gratis via email