设置自定义背景
tv_all.setBackground(new ShapeElement(mContext, ResourceTable.Graphic_round_all_n));
在Graphic下新建一个round_all_n的xml背景文件。
<?xml version="1.0" encoding="UTF-8" ?>
<shape
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<solid
ohos:color="$color:color_f0f"/>
<stroke
ohos:width="1"
ohos:color="$color:color_f0f"/>
<corners
ohos:left_bottom_x="3fp"
ohos:left_bottom_y="3fp"
ohos:left_top_x="3fp"
ohos:left_top_y="3fp"
ohos:right_bottom_x="0fp"
ohos:right_bottom_y="0fp"
ohos:right_top_x="0fp"
ohos:right_top_y="0fp"/>
</shape>
设置自定义文本颜色
tv_all.setTextColor(new Color(CommonUtils.getColor(mContext,ResourceTable.Color_color_w)));
getcolor方法
public static int getColor(Context context, int resourceId) {
try {
return context.getResourceManager().getElement(resourceId).getColor();
} catch (IOException | NotExistException | WrongTypeException e) {
LogUtils.i(TAG, "some exception happend");
}
return GET_COLOR_STATE_FAILED;
}
自定义颜色位置在color.json下