Android: 更改可绘制对象的背景
Android: Changing background of a drawable
我的应用中的评论 activity 布局有一个圆角可绘制背景 (layout_bg_round_corners):
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/deep_orange"/>
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
可绘制对象的背景透出白色。相反,我希望它们是黑色的。
如何设置可绘制对象的背景颜色?
这是我设置父视图布局的方式:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/layout_bg_round_corners"
在布局中 xml 添加标签 android:background="颜色代码"
或者您可以通过将颜色代码替换为可绘制对象 ID 来将背景设置为可绘制对象。
除非我完全误解了你,否则 layer-list drawable 应该可以解决问题:)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#000000" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/deep_orange"/>
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
</item>
</layer-list>
嘿,你需要给相关布局设置黑色,试试这个
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#000000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/layout_bg_round_corners">
我的应用中的评论 activity 布局有一个圆角可绘制背景 (layout_bg_round_corners):
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/deep_orange"/>
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
可绘制对象的背景透出白色。相反,我希望它们是黑色的。
如何设置可绘制对象的背景颜色?
这是我设置父视图布局的方式:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/layout_bg_round_corners"
在布局中 xml 添加标签 android:background="颜色代码"
或者您可以通过将颜色代码替换为可绘制对象 ID 来将背景设置为可绘制对象。
除非我完全误解了你,否则 layer-list drawable 应该可以解决问题:)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#000000" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/deep_orange"/>
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
</item>
</layer-list>
嘿,你需要给相关布局设置黑色,试试这个
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#000000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/layout_bg_round_corners">