如何设置shaperawable的边框并将颜色填充为不同的颜色

时间:2018-06-18 10:45:13

标签: java android android-studio

我需要将shaperawable的边框颜色和填充颜色设置为不同的颜色。如何设置两种颜色并将形状设置为填充和描边?

说我有这个:

        ShapeDrawable border = new ShapeDrawable(new RectShape());

        border.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
        border.getPaint().setColor(Color.WHITE);
        border.getPaint().setStrokeColour(Color.BLACK); //???????? How to do

编辑:我的问题不是Android ShapeDrawable set Background and Border programmatically的重复,因为该问题的唯一答案不清楚,对我没有帮助。

2 个答案:

答案 0 :(得分:0)

您可能希望以XML格式定义drawable。它看起来像这样:

use strict;
use warnings;

print "connect to Perforce Server\n";
my $connection=`echo Ra@@@g|p4 -u raj login`;
if ( !$connection ) {
    print "Failed to connect to Perforce Server\n";
    exit(1);
}

my $status = system("p4 sync");
if ($status == 0) {
    my $workon = system("workon demo_project");
    my $build = system("gmake –f Makefile bin");         
} else {
    exit 1;
}

答案 1 :(得分:0)

you might define an xml like below and use it where you need:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:radius="7dp"
        android:topRightRadius="7dp"
        android:topLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:bottomLeftRadius="7dp" />
    <solid android:color="@android:color/white" />
    <stroke android:width="1dip" android:color="#c9d1d7"/>
</shape>