Android,创建渐变边框?

时间:2016-05-28 07:48:28

标签: android xml gradient

我知道在stackoverflow发布所有类似帖子之后,这令人沮丧。我已经浏览了很多帖子,但我真的无法解决我的问题。所以请帮忙!我想通过xml设置渐变边框,如图像:

enter image description here

我怎样才能实现这个目标?

1 个答案:

答案 0 :(得分:8)

根据您的设计自定义,创建一个可绘制的文件:

case R.id.ll_date:
                    showDialog(999);
                    break;

And Dialog is

@Override
    protected Dialog onCreateDialog(int id) {
        if (id == 999) {
            DatePickerDialog datePickerDialog = new DatePickerDialog(mActivity, myDateListener, currYear, currMonth, currDay);
            return new DatePickerDialog(this, myDateListener, currYear, currMonth, currDay);
        }
        return null;
    }

        private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker arg0, int year, int month, int day) {
            Calendar selectedCal = Calendar.getInstance();
            selectedCal.set(year, month, day);
            DateFormat df = new SimpleDateFormat("MM/dd/yyyy", new Locale("en_US"));
            String date = df.format(new Date());
            String selectedDate = df.format(selectedCal.getTime());
            try {
                Date current = df.parse(date);
                Date selected = df.parse(selectedDate);
                Log.print("Date =================== " + day);
                if (selected.before(current)) {
                    showSnackbar(txtDate, getString(R.string.alert_can_not_able_previous_date));
                } else {
                    int month1 = month + 1;
                    String Date = (month1 < 10 ? ("0" + month1) : (month1)) + "/" + (day < 10 ? ("0" + day) : (day)) + "/" + year;
                    txtDate.setText(Date);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    };

并设置为布局的背景