Android 未设置颜色为的曲面视图边框

Android 未设置颜色为的曲面视图边框,android,Android,我想在运行时使用颜色设置曲面视图边框。我是这样做的,但它不起作用 //Video View to play the vidoes ads. surfaceView = new SurfaceView(context); GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setStroke(5, Color.MAGENTA); sur

我想在运行时使用颜色设置曲面视图边框。我是这样做的,但它不起作用

//Video View to play the vidoes ads.
surfaceView = new SurfaceView(context);
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setStroke(5, Color.MAGENTA);
surfaceView.setBackgroundDrawable(drawable);
surfaceView.setPadding(10, 10, 10, 10);
当我进行设置时,此视频将停止显示

请帮我使它正常工作


提前感谢

您可以创建边框表单xml样式,然后设置为imageview或任何其他视图

<shape
    android:padding="10dp"
    android:shape="rectangle" >

    <solid android:color="give hexa code of your color" />

    <stroke
        android:width="2dp" />

    <corners 
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" />

</shape>

您可以动态设置背景色,并为imageLike图像提供边距;图像.背景颜色(颜色.白色)@YogeshTatwal如何设置颜色名称“绿色”的颜色。如果我收到蓝色,那么它应该设置为蓝色,首先告诉我你得到颜色代码,如果不是,那么你必须使用If-else条件,并告诉我你有多少颜色???@yogestatwal我从web服务得到颜色“绿色”、“红色”等。如果我得到了绿色,那么我需要设置它。在没有ifs条件的情况下,有没有通用的方法来处理这个问题
imageView1.setBackgroundDrawable(R.drawable.rectangle);