madara uchiha madara uchiha - 3 months ago 6
Android Question

When edittext is select, theme/style does not change

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 any edittext then line blow edittext remain white.please check this image for more clarification

Xml Code:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.science.character.fragments.Email_signup_Fragment">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".activities.Email_signupActivity"
>
<ImageView
android:id="@+id/img_backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/backbutton1"/>

<TextView
android:id="@+id/text_sign_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/email_sign_up_text"
android:fontFamily="sans-serif-thin"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="@android:color/white"
android:textSize="25dp"
/>

<RelativeLayout
android:id="@+id/relativelayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/text_sign_up"
android:layout_above="@+id/btn_create_account"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
>


<EditText
android:id="@+id/edittext_firstname"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="first name"
android:text=""
android:fontFamily="sans-serif-light"

android:singleLine="true"
android:textAlignment="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_gravity="center_horizontal" />
<EditText
android:id="@+id/edittext_lastname"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="last name"
android:text=""
android:fontFamily="sans-serif-light"
android:singleLine="true"
android:textAlignment="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal" />


<EditText
android:id="@+id/edittext_email"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="email"
android:text=""
android:fontFamily="sans-serif-light"
android:singleLine="true"
android:textAlignment="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal" />

<EditText
android:id="@+id/edittext_password"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:text=""
android:inputType="textPassword"
android:fontFamily="sans-serif-light"
android:hint="Password"
android:singleLine="true"
android:textAlignment="center"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal" />
<EditText
android:id="@+id/edittext_confirm_password"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:inputType="textPassword"
android:text=""
android:fontFamily="sans-serif-light"
android:hint="Confirm Password"
android:textAlignment="center"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal" />


</LinearLayout>

</RelativeLayout>
<Button
android:id="@+id/btn_create_account"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="@string/create_account_button"
android:textColor="@android:color/white"
android:fontFamily="sans-serif-light"
android:textSize="24dp"
android:textAllCaps="false"
android:background="@drawable/button_background"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:layout_above="@+id/text_terms_condition"
/>

<TextView
android:id="@+id/text_terms_condition"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:text="@string/terms_and_conditions"
android:textColor="@android:color/white"
android:textSize="12dp"
android:fontFamily="sans-serif-thin"
android:textAllCaps="false"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>

</RelativeLayout>



Answer
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"
Comments