久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

EditText 的子類看起來(lái)與 Android 4 上的普通 EditTex

Child class of EditText looks different than normal EditText on Android 4(EditText 的子類看起來(lái)與 Android 4 上的普通 EditText 不同)
本文介紹了EditText 的子類看起來(lái)與 Android 4 上的普通 EditText 不同的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

這是我在開(kāi)發(fā)真實(shí)應(yīng)用程序時(shí)發(fā)現(xiàn)的錯(cuò)誤",但我創(chuàng)建了一個(gè)空白項(xiàng)目來(lái)重現(xiàn)它.

This is a 'bug' that I discovered while working on a real app, but I created a blank project to reproduce it.

我有以下布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:id="@+id/root"
    android:orientation="vertical"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <com.example.test.testapp.MyEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>

MyEditText 類如下所示:

public class MyEditText extends EditText {

    public MyEditText(Context context){
        super(context);
    }

    public MyEditText(Context context, AttributeSet attrs){
        super(context, attrs);
    }


    public MyEditText(Context context, AttributeSet attrs, int defStyle){
        super(context, attrs, defStyle);
    }


}

我的 styles.xml 文件是空的,除了主題

My styles.xml file is empty except for the Theme

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>

我希望 MyEditText 看起來(lái)像普通的 EditText 并且它在 Android 5.0 上是這樣,但在 Android 2.3.7、Android 4.1.3 或 Android 4.4 上卻不是.4.

I would expect the MyEditText to look like the normal EditText and it does on Android 5.0, but not on Android 2.3.7, Android 4.1.3 or Android 4.4.4.

在那些 Android 版本上,EditText 的顏色不同,正常的在聚焦時(shí)有青色下劃線,自定義的有黑色下劃線:

On those Android versions the EditTexts differ in color, the normal one has a cyan underline when focused, the custom one has a black underline:

為什么會(huì)發(fā)生這種情況,我該如何預(yù)防?

Why is this happening and how can I prevent it?

編輯/更新:

Google 似乎已經(jīng)解決了這個(gè)問(wèn)題 在支持庫(kù)中引入 AppCompatEditText 類等.

Google seems to have adressed this in the support library by introducing, amongst others, an AppCompatEditText class.

推薦答案

為什么會(huì)這樣

因?yàn)槟褂玫氖?AppCompat.引用 關(guān)于該主題的博文:

Because you are using AppCompat. Quoting the blog post on the subject:

問(wèn):為什么我的 EditText(或上面列出的其他小部件)在我的棒棒糖之前的設(shè)備上沒(méi)有正確著色?

Q: Why is my EditText (or other widget listed above) not being tinted correctly on my pre-Lollipop device?

答:AppCompat 中的小部件著色通過(guò)攔截任何布局膨脹并在其位置插入一個(gè)特殊的著色感知版本的小部件來(lái)工作.對(duì)于大多數(shù)人來(lái)說(shuō),這可以正常工作,但我可以想到一些不起作用的場(chǎng)景,包括:

A: The widget tinting in AppCompat works by intercepting any layout inflation and inserting a special tint-aware version of the widget in its place. For most people this will work fine, but I can think of a few scenarios where this won’t work, including:

  • 您擁有自己的自定義小部件版本(即您已擴(kuò)展 EditText)
  • 您正在創(chuàng)建沒(méi)有 LayoutInflater 的 EditText(即,調(diào)用 new EditText()).

因此,該行為是預(yù)期的.AppCompat 向后移植提供了一些輕量級(jí)的著色向后移植,但它不能處理所有情況.

So, the behavior is expected. The AppCompat backport provides some lightweight backporting of tinting, but it's not going to handle all cases.

如何預(yù)防?

即開(kāi)即用:

  • 不要?jiǎng)?chuàng)建 EditText 的子類,或者

在 AppCompat 上運(yùn)行時(shí),查找色調(diào)并弄清楚如何自己應(yīng)用它,或許可以通過(guò)檢查 AppCompat 源代碼(假設(shè)它可用——我沒(méi)有尋找它),或者

When running on AppCompat, look up the tint and figure out how to apply it yourself, perhaps by examining the AppCompat source code (assuming it's available -- I haven't looked for it), or

不要使用 AppCompat,并在 Android 5.0+ 設(shè)備上使用 Theme.Material 查看著色是否按預(yù)期工作

Do not use AppCompat, and see if tinting works as expected using Theme.Material on Android 5.0+ devices

未來(lái)的 AppCompat 可能會(huì)為子類提供某種系統(tǒng)來(lái)參與著色過(guò)程.除了這些之外,可能還有其他解決方案——這些都是我想到的.

It's possible that a future AppCompat could provide some sort of system for subclasses to participate in the tinting process. And there may be other solutions than these -- these are what come to mind.

這篇關(guān)于EditText 的子類看起來(lái)與 Android 4 上的普通 EditText 不同的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開(kāi)的 EditText 中的開(kāi)始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問(wèn)題)
主站蜘蛛池模板: 欧美日韩精品一区二区三区四区 | 国产精品久久视频 | www.中文字幕.com| 国产成人精品亚洲日本在线观看 | 国产精品日韩欧美一区二区三区 | 在线亚洲欧美 | 二区三区视频 | 精品一区二区三区四区在线 | 精品久久99| 91在线看片| 久久伊人在 | 午夜私人影院在线观看 | 日本精品一区二区三区四区 | 欧美日韩在线播放 | 四虎在线播放 | 国产精品久久久久久久久 | 国产福利视频导航 | 欧美精品一区二区三区在线播放 | 久久久免费| 欧美日韩亚洲一区 | 日韩成人av在线播放 | 一区二区三区国产 | 精品国模一区二区三区欧美 | 国产欧美日韩一区二区三区 | 日本一区二区高清不卡 | 成人网在线 | 久久精品国产亚洲一区二区 | 中文字幕在线不卡播放 | 国产精品一级在线观看 | 日韩av免费在线观看 | 久久国产精品免费 | 91精品国产91久久久久久 | 中文字幕韩在线第一页 | 日日夜夜精品视频 | 久久精品一级 | 91视频三区 | 色视频成人在线观看免 | 成年视频在线观看 | 毛片免费看 | 99国产精品久久久久老师 | 日韩欧美在线视频 |