Android:Drawable样式和尺寸单位

3.6 Drawable样式装饰

1、ColorDrawable

ColorDrawable:在res/values/color.xml中添加颜色值,然后@color/颜色名获取资源;

示例:color.xml





    #008577

    #00574B

    #D81B60

    

    #FFB6C1

    

    #FF000000

XML布局文件中使用颜色

示例:














Activity中设置颜色

示例:

public class ColorDrawableActivity extends Activity {

        //上下文

        private Context mContext;

        private TextView textView;

        private TextView textView1;

        @Override

        protected void onCreate( Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);

                setContentView(R.layout.learn_color_drawable);

                mContext = ColorDrawableActivity.this;

                textView = findViewById(R.id.tv_1);

                textView1=findViewById(R.id.tv_2);

                //设置颜色,自定义,需要0x开头,透明度,6位颜色值

                int color = 0xff008577;

                textView.setBackgroundColor(color);

                //获取color.xml中颜色

                int color1=getResources().getColor(R.color.colorAccent);

                //获取系统颜色

                int color2= Resources.getSystem().getColor(android.R.color.holo_blue_dark);

                textView1.setBackgroundColor(color2);

        }

}

2、NinepatchDrawable

NinepatchDrawable:点9图,图片:图片名.9.png等,使用NinePatchEditor工具编辑获得图片资源;

示例:drawable下创建xml资源文件







Layout布局文件使用.9图

3、ShapeDrawable

ShapeDrawable:形状Drawable资源,包括直线,边框,环形,方形,椭圆等;

:

 ~ visible:设置是否可见

 ~ shape:形状,可选:rectangle(矩形,包括正方形),oval(椭圆,包括圆),line(线段),ring(环形)

 ~ innerRadiusRatio:当shape为ring才有效,表示环内半径所占半径的比率,如果设置了innerRadius, 他会被忽略

你可能感兴趣的:(Android,android,开发语言,笔记)