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

EditText 的子類看起來與 Android 4 上的普通 EditTex

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

問題描述

限時送ChatGPT賬號..

這是我在開發真實應用程序時發現的錯誤",但我創建了一個空白項目來重現它.

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 看起來像普通的 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 的顏色不同,正常的在聚焦時有青色下劃線,自定義的有黑色下劃線:

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:

為什么會發生這種情況,我該如何預防?

Why is this happening and how can I prevent it?

編輯/更新:

Google 似乎已經解決了這個問題 在支持庫中引入 AppCompatEditText 類等.

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

推薦答案

為什么會這樣

因為您使用的是 AppCompat.引用 關于該主題的博文:

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

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

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

答:AppCompat 中的小部件著色通過攔截任何布局膨脹并在其位置插入一個特殊的著色感知版本的小部件來工作.對于大多數人來說,這可以正常工作,但我可以想到一些不起作用的場景,包括:

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:

  • 您擁有自己的自定義小部件版本(即您已擴展 EditText)
  • 您正在創建沒有 LayoutInflater 的 EditText(即,調用 new EditText()).

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

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

如何預防?

即開即用:

  • 不要創建 EditText 的子類,或者

在 AppCompat 上運行時,查找色調并弄清楚如何自己應用它,或許可以通過檢查 AppCompat 源代碼(假設它可用——我沒有尋找它),或者

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+ 設備上使用 Theme.Material 查看著色是否按預期工作

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

未來的 AppCompat 可能會為子類提供某種系統來參與著色過程.除了這些之外,可能還有其他解決方案——這些都是我想到的.

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.

這篇關于EditText 的子類看起來與 Android 4 上的普通 EditText 不同的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
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 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 美丽的姑娘观看在线播放 | 色综合久久88 | 美丽的姑娘观看在线播放 | 久久久久久久97 | 亚洲一区二区免费看 | 国产片一区二区 | 久久视频在线免费观看 | 欧美一区二区视频在线观看 | 一区二区三区四区视频 | 久久黄色免费视频 | 一级片免费观看 | 91靠逼视频 | 成人一区二区在线 | 成人短视频在线观看 | 国产一区亚洲 | 久久久久亚洲精品 | 精品久久一区二区三区 | 黄色三级在线观看 | 欧美性猛交xxxx免费看久久久 | 精品一区二区视频 | 久草福利资源 | 日本不卡一区 | 做爰xxxⅹ性生交 | 国产午夜免费视频 | 亚洲亚洲人成综合网络 | 国产一区二区在线播放 | 91久久精品日日躁夜夜躁欧美 | 福利视频午夜 | 国产理论片在线观看 | 一区二区小视频 | 一区二区三区四区精品 | 久久都是精品 | 激情av网| 波多野吉衣一二三区乱码 | 黄色成人在线观看 | 久久99精品久久久久久水蜜桃 | 韩日一区二区 | 日本国产欧美 | 色午夜 | 日本不卡视频在线观看 | 91成人精品一区在线播放 |