简体   繁体   English

为什么android:background对我不起作用?

[英]why android:background doesn't work for me?

my layout file as bellow 我的布局文件如下

<?xml version="1.0" encoding="UTF-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".LimeText" >


    <TextView
        android:id="@+id/file_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ***android:background="@color/red"***
        android:text="@string/untitled" />

    <ScrollView  
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/scroll"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:fadingEdge="none">

            <EditText
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:id="@+id/file_content"
            ***android:background="@android:color/white"***
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dip"
                android:fadingEdge="none"
                android:scrollbars="vertical|horizontal"
                android:gravity="top"
                android:autoText="false"
                android:capitalize="none" />

    </ScrollView>
</LinearLayout>

but no matter how do I change the background, the EditText 's background always stay on black and the ' TextView 's background always be grey. 但是无论如何更改背景, EditText的背景始终保持黑色,而TextView的背景始终为灰色。 the grey TextView is set before, #CCCCCC, but now I want to change it to another color , it cannot. 灰色的TextView之前设置为#CCCCCC,但现在我想将其更改为另一种color ,但不能。

Your color code file must be on this path. 您的颜色代码文件必须在此路径上。

res/values/colors.xml

with following content 具有以下内容

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="edittext_color">#000000</color>
        <color name="text_color">#00FFFF</color>
    </resources>

and now use that in such a way. 现在以这种方式使用它。

<EditText
    android:id="@+id/my_edit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxLength="5"
    android:background="@color/edittext_color" />

Hope this helps. 希望这可以帮助。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以告诉我为什么这个Android代码不起作用吗? - Can someone tell me why this Android Code doesn't work? Android Studio中的背景不起作用 - Background in Android Studio doesn't work Android TranlateAnimation背景不起作用 - Android TranlateAnimation background doesn't work 用于在Android中创建临时文件的文件夹,为什么/ data / local / tmp对我不起作用? - Folder for temporary files creation in android, Why does /data/local/tmp doesn't work for me? 请告诉我,为什么滚动视图在android studio中不起作用? - Please tell me why the scroll view doesn't work in android studio? 为什么 cordova-plugin-background-mode 插件不能在 android 上运行? - Why doesn't the cordova-plugin-background-mode plugin work on android? Android共享元素动画不适用于我 - Android Shared Element Animation doesn't work for me android:background =“#000000”在Android 2.3.6及更低版本中不起作用 - android:background=“#000000” doesn't work in Android 2.3.6 and below Android:为什么捆绑putExtras不起作用? - Android: Why Bundle putExtras doesn't work? Android:为什么AlarmManager不起作用? - Android: why doesn't AlarmManager work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM