我希望能够在我的android应用程序中以最简单的方式将背景颜色更改为白色。
当前回答
有时,文本与背景颜色相同,尝试用android:background="#CCCCCC"进入listview属性,你会看到。
其他回答
你可以使用简单的颜色资源,通常在里面指定
res/values/colors.xml.
use
<color name="red">#ffff0000</color>
并通过android:background="@color/red"使用这个。这种颜色也可以用于其他任何地方,例如作为文本颜色。以同样的方式在XML中引用它,或者在代码中通过
getResources().getColor(R.color.red).
你也可以使用任何可绘制的资源作为背景,使用android:background="@drawable/mydrawable"(这意味着9patch drawables,正常位图,形状drawables, ..)。
使用渐变背景的最好方法,因为它不会增加应用程序的大小,图像是android应用程序的毒药,所以尽量少使用它,而不是使用一种颜色作为背景,你可以在一个背景中使用多种颜色。
你可以试试这种方法
android:background="@color/white"
如果你想为整个活动添加背景色
<RelativeLayout
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:background="#1de9b6"
tools:context="com.example.abc.myapplication.MainActivity">
</RelativeLayout>
如果你想使用背景视图
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Andrios"
android:background="@color/colorAccent" />
希望这能有所帮助!
有时,文本与背景颜色相同,尝试用android:background="#CCCCCC"进入listview属性,你会看到。
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件