选择edittext后,主题/样式不会更改 [英] When edittext is select, theme/style does not change

查看:46
本文介绍了选择edittext后,主题/样式不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的注册表单中有Edittext.当用户触摸edittext时,edittext框变为绿色(表示已选择edittext),我不希望这样做.当用户选择任何Edittext时,行吹动Edittext保持白色.请检查此图像以得到更多澄清

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代码:

<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>

推荐答案

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"/>

其他解决方案:在可绘制对象中创建选择器xml文件

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>

将此行添加到edittext

Add this line in edittext

android:background="@drawable/xml name"

这篇关于选择edittext后,主题/样式不会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆