我希望能够在我的android应用程序中以最简单的方式将背景颜色更改为白色。
当前回答
android:背景= " # 64 b5f6 " 您可以根据自己的规范或需要更改'#'后的值,这取决于您想如何使用它们。 下面是一个示例代码:
< TextView android:文本= " Abir " android: layout_width = " match_parent " android: layout_height = " wrap_content " android: textSize = " 24 sp " android:背景= " # D4E157 " / >
谢谢!
其他回答
你需要使用android:background属性,例如
android:background="@color/white"
此外,您还需要在strings.xml中为white添加一个值
<color name="white">#FFFFFF</color>
编辑:2012年11月18日
8字母颜色代码的前两个字母提供alpha值,如果你使用html 6字母颜色符号,颜色是不透明的。
例如:
我希望能够改变背景颜色为白色在我的 最简单的Android应用程序。
题目说的是最简单的方法,所以在这里。
在所有父视图中设置parentViewStyle。像大多数家长视图你的活动,片段和对话框。
<LinearLayout style="@style/parentViewStyle">
... other components inside
</LinearLayout>
把这个样式放在res>values>styles.xml中
<style name="parentViewStyle">
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item>
<item name="android:background">@color/white</item> // set your color here.
<item name="android:orientation">vertical</item>
</style>
通过这种方式,你不需要在未来改变背景颜色很多次。
最简单的方法是在layout.xml或/res/layout/activity_main.xml的主节点中添加android:background="#FFFFFF":
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="20sp"
android:background="#FFFFFF">
</TextView>
在布局中,改变背景使用这个。
android:background="@color/your_color"
在程序中可以使用这个。例如:Texview背景色
TextView tvName = (TextView) findViewById(R.id.tvName);
tvName.setBackgroundColor(getResources().getColor(R.color.your_color));
你可以使用简单的颜色资源,通常在里面指定
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, ..)。
推荐文章
- 警告: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文件