首页 新闻 赞助 找找看

android atudio Button按钮无法改变颜色。

0
悬赏园豆:200 [已解决问题] 解决于 2020-10-30 10:20

我在网上查了好久,都是和selector有关的,但是android:background="@color/white"都变不了颜色,这是什么问题啊,好像被默认了,输入Buttpn控件就默认这个样子了,求解决


bt_shape.xml,head_user.png,log_user.png,log_pwd,tx_selector.xml,colors.xml文件中<color name="blue_1">#1296db</color>这一行代码,activity_main中的代码,这些是我自己建的,除此之外没有再建其他文件,其余都是我打代码之前就有的

问题补充:

我发现Button按钮的颜色改变与themes.xml

文件中
<item name="colorPrimary">@color/blue_1</item>有关,求解释

TrueLoveBeauty的主页 TrueLoveBeauty | 初学一级 | 园豆:24
提问于:2020-10-29 20:01
< >
分享
最佳答案
0

是android和v26自带的主题原因

TrueLoveBeauty | 初学一级 |园豆:24 | 2020-10-29 22:38
其他回答(3)
0

android:background="#FFFFFF"

收获园豆:100
小小咸鱼YwY | 园豆:3210 (老鸟四级) | 2020-10-29 20:16

不好意思,试过了,不行哎

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-29 20:17

@TrueLoveBeauty: 你把你这个界面的代码makdow格式贴出来

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3210 (老鸟四级) | 2020-10-29 20:18

就是这个background无效了里面输入什么都变不了,放在TextVew可以改变

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-29 20:19

@TrueLoveBeauty: 你贴出来你的代码,速度,等会就回家了

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3210 (老鸟四级) | 2020-10-29 20:20

@小小咸鱼YwY: <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:orientation="vertical"
tools:context=".MainActivity">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp"
    app:srcCompat="@drawable/head_user" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp"
    android:layout_marginBottom="20dp"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/et_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/tx_selector"
        android:drawableLeft="@drawable/log_user"
        android:ems="10"
        android:hint="请输入用户名"
        android:inputType="text"
        android:paddingLeft="8dp"
        android:textSize="20dp" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/et_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/tx_selector"
        android:drawableLeft="@drawable/log_pwd"
        android:hint="请输入密码"
        android:inputType="textPassword"
        android:paddingLeft="8dp"
        android:textSize="20dp" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dp"
    android:layout_marginBottom="50dp"
    android:gravity="center_horizontal"
    android:orientation="horizontal">

    <Button
        android:id="@+id/bt_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="注册"
        android:textSize="15dp"/>

    <Button
        android:id="@+id/bt_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="@color/white"
        android:clickable="true"
        android:text="登录"
        android:textSize="30dp"/>

    <Button
        android:id="@+id/bt_forget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="忘记密码?"
        android:textSize="15dp"/>
</LinearLayout>

</LinearLayout>

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-29 20:21

@TrueLoveBeauty:
属性设置应该没问题,你项目全局是不是设置了什么样式

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3210 (老鸟四级) | 2020-10-29 20:24

@小小咸鱼YwY: 项目全局,我是没有设置

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-29 20:26

@小小咸鱼YwY: 是不是那里给默认设置了,以前用的eclipse对android studio 不是很熟悉

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-29 20:27

@TrueLoveBeauty: 这部分代码倒是没什么问题,不过设置颜色还是#FFFFFF这样设置比较多

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3210 (老鸟四级) | 2020-10-29 20:32

@小小咸鱼YwY:

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-29 20:33
0

android:theme="@null" 你是不是需要一句这个。。

收获园豆:100
小石轩 | 园豆:304 (菜鸟二级) | 2020-10-30 10:05


我尝试一下,谢谢

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-30 10:11

不行呢,parent=“”这给锁死了,在activity_main.xml里怎么改Button样式都无效

支持(0) 反对(0) TrueLoveBeauty | 园豆:24 (初学一级) | 2020-10-30 10:18

parent=“”这个可以去掉的。。单独给它弄个主题试试吧。。

支持(0) 反对(0) 小石轩 | 园豆:304 (菜鸟二级) | 2020-10-30 10:32
0

我知道了,去这里面

这句不管之前是什么改成我这样的就好了

歐瀚 | 园豆:5 (初学一级) | 2020-11-19 14:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册