当选择edittext时,主题/样式不会改变

2024-06-08

我的注册表单中有 Edittext。当用户触摸编辑文本时,编辑文本框变为绿色(表示选择了编辑文本)我不希望这样。当用户选择任何编辑文本时,行吹编辑文本保持白色。请检查此图片以获取更多说明 https://i.stack.imgur.com/slgjY.png

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

其他解决方案:在drawables中创建选择器xml文件

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

在编辑文本中添加这一行

android:background="@drawable/xml name"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当选择edittext时,主题/样式不会改变 的相关文章

  • Firestore中一步调用add时如何获取id?

    我知道获取 id String cityId db collection cities document getId db collection cities document cityId set city 但更容易 db collect
  • 如何使按钮的高度与另一个元素的高度相匹配?

    我想在 EditText 旁边放置一个按钮 并且希望它们的高度匹配 例如 从内置的 Android 浏览器 Go 按钮与 EditText 字段的高度相同 我知道我可以将这两个视图包装在父布局视图中 并将它们的高度都设置为 fill par
  • 检索项目的父级时出错:找不到与给定名称“Theme.Base.AppCompat.DialogWhenLarge.Base”匹配的资源

    2014 11 22 07 46 34 aa D EclipseAndroidWorkspace Leaning exercise appcompat v7 res values large v14 themes base xml 19 e
  • PhoneGap - 构建 PhoneGap Android 应用程序在 Linux 上出现编译错误

    我在我的 linux ubuntu 12 04 机器上构建phonegap android 应用程序时遇到错误 我已经安装了nodejs 将JAVA HOME ANT HOME ANDROID HOME vars和 JAVA HOME bi
  • 在TextView中设置显示不同的语言。

    我有一些不同语言的字符串 如下所示 String aa arbic String arr hindi String str1 T bingen systemportef lje Strings tr2 Das ist nicht Engli
  • 如何在 Android API 上使用 setImageTintList() < 21

    imgView setImageTintList getResources getColorStateList R color my clr selector 它说 调用需要 API 级别 21 如何让它在 API 21 以下的 Andro
  • Android WebView 不会滚动

    我有一个WebView在 Android 4 2 中加载一个本地 HTML使用javascript 放置在资产文件夹中 我的问题是 我无法在我的 WebView 中滚动任何 我通过类似的问题尝试了很多事情和建议 但没有任何效果 我的 Htm
  • Boot BroadcastReceiver 在小米设备上不起作用

    我有一个关注者BroadcastReceiver它应该在启动完成后运行 我已经在我的上测试过了小米设备 Redmi 1s 它没有运行 而在其他设备上 例如Samsung它正在按预期运行 public class DeviceBootRece
  • 如何终止一个 Observable?

    我有一个 Observable 如果不满足某个条件 即某个网站的响应不成功 我想终止它 以便我可以重新查询该网站 并再次调用该 observable 我该如何去做呢 这就是我想做的 Observable create new Observa
  • FragmentPagerAdapter 和 FragmentStatePagerAdapter 有什么区别?

    有什么区别FragmentPagerAdapter and FragmentStatePagerAdapter About FragmentPagerAdapter谷歌的指南说 此版本的寻呼机最适合在有少数人的情况下使用 通常需要分页的静态
  • 使用 Gradle 将 Lint 结果发布到 Sonar

    我正在尝试使用 Gradle 将 Lint 结果发布到声纳服务器 其他分析结果已发布 但 Lint 结果未发布 有谁有让这个工作的经验吗 我找不到任何附加信息 声纳的版本是3 5 1 Gradle的版本是1 10 顶层构建文件如下所示 有
  • 房间数据库:插入的ID始终为0

    我正在尝试创建列表项的房间数据库 我在这里遵循这个例子 https medium com mindorks room kotlin android architecture components 71cad5a1bb35 https med
  • MATCH_PARENT 如果同级视图较大,则 WRAP_CONTENT 如果同级视图较小

    我在布局中有两个视图 我会打电话给他们View A and View B分别 A B 父布局的高度 包括View A and View B is WRAP CONTENT 这里 高度为View B is WRAP CONTENT 也就是说
  • Android 点击列表视图

    我有一个包含 15 个项目的列表视图 当我单击任何项 目时 我想更改屏幕 意图 如何更改 Android 中所选项目的活动 有教程或者源码吗 您可以使用ListView s setOnItemClickListener 并在此方法的实现中启
  • 观察Eclipse中很长的String内容

    由于 LogCat 会截断长字符串 因此我使用 FileOutputStream 来检查很长字符串的内容来解决此问题 它可以工作 但它迫使我 adb pull 该文件 与在 LogCat 上观看相比 这不是很方便 Eclipse中有没有其他
  • android中单例的问题

    我有一个 Android 应用程序 其中有几个活动 每个活动都会下载一个 xml json 提要 对其进行解析并将其推送到一个单例 通常作为数组列表 然而 在经历了各种活动之后 单例似乎正在消亡 并且大多数早期下载的数组列表现在都是空的 为
  • 实现导航抽屉后通知栏呈灰色

    我正在尝试学习 Android 中导航抽屉的实现 在一项活动中 我将导航抽屉置于状态栏 透明 下方和应用栏上方 一切正常 左屏幕截图 在同一应用程序的另一个活动中 我试图创建在应用程序栏下方拉起的导航抽屉 但在这里 状态栏由于某种原因变成灰
  • 使用 Glide 进行缩放和遮罩

    我只是想看看是否有人可以为我指明正确的方向 以学习如何使用 Glide 来完成此任务 我们有一个包含内容的页面 内容显示为单个图像 想想 杂志页面的图像 在轻松阅读模式下 我想将第一块居中并缩放 文本内容并屏蔽其余内容 单击 下一步 时 我
  • Android 模拟器在截屏时不断退出

    我不记得我是否曾经修改过 Android 模拟器的设置 但我一直在使用 Android Studio 在 Android 模拟器上测试我的应用程序 每次我截屏时 它都会崩溃 我尝试删除 擦除并创建一个新的模拟器 这些都不起作用 我还尝试使用
  • 在 api 21 下将主题应用到对话框时出现奇怪的行为[重复]

    这个问题在这里已经有答案了 我正在使用主题 Theme AppCompat Light NoActionBar 在我的应用程序中 我想让我的一些对话框应用深色 AppCompat 主题 所以 我为对话框创建了样式 当父级是 Theme Ap

随机推荐