Custom DatePicker

前端 未结 3 2309
有刺的猬
有刺的猬 2021-02-20 11:54

I ve been stuck on a DatePicker problem for several and i can\'t seem to find any solution.

I currently have a DatePickerDialog which fits quite well to my needs YET I

3条回答
  •  名媛妹妹
    2021-02-20 12:00

    Its kinda hacky, but if you look at the layout for the DatePicker you can see its a FrameLayout containing 3 sub-views. So I was wanting the hide the year and did this.

        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ViewGroup group = (ViewGroup) findViewById(R.id.picker);
        group = (ViewGroup) group.getChildAt(0);
        Toast.makeText(this, String.format("%s children", group.getChildCount()), Toast.LENGTH_SHORT).show();
        try{
            group.getChildAt(2).setVisibility(View.GONE);
                // 2 for year, 1 for day, 0 for month
        }catch(Exception e){
            Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
        }
    }
    

    This gets the framelayout of the picker and then hides its 3rd child which is the year. Hope this helps!

提交回复
热议问题