EditText에서 선 색상을 변경하는 방법 EditText의 색상 줄을 Holo에서 (예를 들어) 빨간색으로

내 레이아웃 xml 파일에서 EditText를 작성하고 있습니다.

그러나 EditText의 색상 줄을 Holo에서 (예를 들어) 빨간색으로 변경하고 싶습니다. 어떻게 할 수 있습니까?

여기에 이미지 설명을 입력하십시오



답변

@ Jérôme Van Der Linden 덕분에 모든보기에 무료로 사용할 수있는 최고의 도구입니다 .

Android Holo Colors Generator를 사용하면 EditTextAndroid 응용 프로그램에 맞는 고유 한 색상으로 스피너와 같은 Android 구성 요소를 쉽게 만들 수 있습니다 . 필요한 9 개의 패치 자산과 관련 XML 드로어 블 및 스타일을 생성하여 프로젝트에 바로 복사 할 수 있습니다.

http://android-holo-colors.com/

업데이트 1

이 도메인은 만료 된 것으로 보이지만 프로젝트는 여기서 찾을 수있는 오픈 소스입니다

https://github.com/jeromevdl/android-holo-colors

시도 해봐

이 이미지는 배경에 넣어 EditText

android:background="@drawable/textfield_activated"

여기에 이미지 설명을 입력하십시오


업데이트 2

API 21 이상의 경우 다음을 사용할 수 있습니다 android:backgroundTint

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Underline color change"
        android:backgroundTint="@android:color/holo_red_light" />

업데이트 3
지금 우리는 다시 지원합니다AppCompatEditText

참고 : android : backgroundTint 대신 app : backgroundTint 를 사용해야 합니다.

<android.support.v7.widget.AppCompatEditText
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:hint="Underline color change"
    app:backgroundTint="@color/blue_gray_light" />


답변

이전 답변이 마음에 들지 않습니다. 가장 좋은 해결책은 다음을 사용하는 것입니다.

<android.support.v7.widget.AppCompatEditText

      app:backgroundTint="@color/blue_gray_light" />

android:backgroundTint대한 EditText에서만 작동 API21의 + . 이 때문에 지원 라이브러리 및를 사용해야합니다 AppCompatEditText.

참고 : 우리는 app:backgroundTint대신에 사용해야 합니다android:backgroundTint

AndroidX 버전

<androidx.appcompat.widget.AppCompatEditText

      app:backgroundTint="@color/blue_gray_light" />


답변

다음과 같이 EditText의 배경을 색조로 지정하여 EditText의 밑줄 색상을 빠르게 변경할 수도 있습니다.

<EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Something or Other"
            android:backgroundTint="@android:color/holo_green_light" />


답변

에 대한 API (21) 아래에, 당신은에 테마 속성을 사용할 수 있습니다 EditText
스타일 파일에 코드 아래에 넣어

<style name="MyEditTextTheme">
    <item name="colorControlNormal">#FFFFFF</item>
    <item name="colorControlActivated">#FFFFFF</item>
    <item name="colorControlHighlight">#FFFFFF</item>
</style>

이 스타일을 다음 EditText과 같이 사용하십시오

<EditText
    android:id="@+id/etPassword"
    android:layout_width="match_parent"
    android:layout_height="@dimen/user_input_field_height"
    android:layout_marginTop="40dp"
    android:hint="@string/password_hint"
    android:theme="@style/MyEditTextTheme"
    android:singleLine="true" />


답변

프로그래밍 방식으로 다음을 시도 할 수 있습니다.

editText.getBackground().mutate().setColorFilter(getResources().getColor(android.R.color.holo_red_light), PorterDuff.Mode.SRC_ATOP);


답변

가장 좋은 방법은 테마에 의한 것이라고 생각합니다.

<style name="MyEditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorControlNormal">@color/black</item>
        <item name="colorControlActivated">@color/action_blue</item>
        <item name="colorControlHighlight">@color/action_blue</item>
</style>

<style name="AddressBookStyle" parent="Theme.AppCompat.Light.DarkActionBar">
     <item name="android:layout_width">match_parent</item>
     <item name="android:layout_height">wrap_content</item>
     <item name="android:textSize">13sp</item>
     <item name="android:theme">@style/MyEditTextTheme</item>
</style>

<android.support.v7.widget.AppCompatEditText
            style="@style/AddressBookStyle"/>


답변

편집 텍스트의 밑줄 색을 변경하려면

전체 앱이이 스타일을 공유하도록하려면 다음과 같은 방법으로 수행 할 수 있습니다.

(1) styles.xml 파일로 이동하십시오. Theme.AppCompat.Light.DarkActionBar의 부모를 상속받는 AppTheme (내 경우)는 앱에서 모든 스타일 파일의 기본 부모가됩니다. 이름을 “AppBaseTheme”로 변경하십시오. 이름이 AppTheme이고 방금 편집 한 AppBaseTheme에서 상속 된 다른 스타일을 바로 아래에 만듭니다. 다음과 같이 보일 것입니다 :

<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="windowActionBar">false</item>
    <!--see http://www.google.com/design/spec/style/color.html#color-color-palette-->
    <item name="colorPrimary">@color/material_brown_500</item>
    <item name="colorPrimaryDark">@color/material_brown_700</item>
    <item name="colorAccent">@color/flamingo</item>

<style name="AppTheme" parent="AppBaseTheme">
    <!-- Customize your theme here. -->
</style>

그런 다음 “ColorAccent”를 EditText 선 색이 원하는 색으로 변경하십시오.

(2) style.xml이있는 다른 값 폴더가있는 경우이 단계는 매우 중요합니다. 해당 파일은 이전 상위 xml 파일에서 상속되기 때문입니다. 예를 들어, values-19 / styles.xml이 있습니다. 이것은 Kitkat 이상을위한 것입니다. 부모를 AppBaseTheme로 변경하고 부모의 색상을 무시하지 않도록“colorAccent”를 제거하십시오. 또한 버전 19와 관련된 항목을 유지해야합니다. 그러면 다음과 같이됩니다.

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>