When edittext is select, theme/style does not change

前端 未结 4 1589
长发绾君心
长发绾君心 2021-01-26 09:56

I have Edittext in my signup form. When user touch on edittext then edittext box turn to green( which represent that edittext is selected ) i don\'t want this. when user select

相关标签:
4条回答
  • 2021-01-26 10:09
    In your styles.xml
    
    <style name="EditTextTheme">
      <item name="colorControlNormal">#ffffff</item>
    </style>
    
    apply theme for edittext
    
    <EditText
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:theme="@style/EditTextTheme"/>
    

    Other solution: Create selector xml file in drawables

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff" />
    <stroke android:width="1dip" android:color="#ff9900" />
    </shape>
    

    Add this line in edittext

    android:background="@drawable/xml name"
    
    0 讨论(0)
  • 2021-01-26 10:16

    Use latest material library

    app/build.gradle

    implementation 'com.google.android.material:material:1.2.0-alpha06'
    

    styles.xml

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

    layout XML

        <com.google.android.material.textfield.TextInputLayout
            style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
            android:id="@+id/text_input_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            >
            <EditText
                android:id="@+id/edit_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="User Name"
                android:text="Chandler"
                android:textCursorDrawable="@null"
                />
        </com.google.android.material.textfield.TextInputLayout>
    

    Kotlin code

        text_input_layout.boxStrokeColor = Color.CYAN
        text_input_layout.defaultHintTextColor = ColorStateList.valueOf(Color.YELLOW)
        text_input_layout.setErrorTextColor(ColorStateList.valueOf(Color.RED))
        text_input_layout.setErrorIconTintList(ColorStateList.valueOf(Color.RED))
        edit_text.backgroundTintList = ColorStateList.valueOf(Color.LTGRAY)
    

    When the textfield is focused/selected/highlighted:

    When the textfield is in error state:

    0 讨论(0)
  • 2021-01-26 10:19

    Go To your styles.xml and change your Application Theme to this:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/white</item>  CHANGE THIS LINE
    </style>
    
    0 讨论(0)
  • 2021-01-26 10:26

    I had issues with changing the global theme, I just wanted one EditText not all of them so the setting the globals styles was not the right answer.

    Instead I just did this:

    <android.support.design.widget.TextInputEditText
        android:id="@+id/car_seller_notes_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Hint"
        android:maxLength="1000"
        android:background="@drawable/edit_text_myunderline"/>
    

    edit_text_myunderline.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <!-- Draw a 2dp width border around shape -->
                <stroke android:color="@color/edit_text_underline_color" android:width="2dp" />
            </shape>
        </item>
        <!-- Overlap the left, top and right border using background color  -->
        <item android:bottom="2dp">
            <shape android:shape="rectangle">
                <solid android:color="@color/window_background"/>
            </shape>
        </item>
    </layer-list>
    
    0 讨论(0)
提交回复
热议问题