Add buttons to PreferenceFragment

后端 未结 4 1987
野性不改
野性不改 2021-02-14 05:48

I want to add a couple buttons to the bottom of my preferences screen for setting defaults and restoring defaults. This answer doesn\'t cover how to do this using PreferenceFrag

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 06:05

    I modified the previous post a little bit, so that the button will get attached at the bottom of the view.

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            LinearLayout v = (LinearLayout) super.onCreateView(inflater, container, savedInstanceState);
    
            Button btn = new Button(getActivity().getApplicationContext());
            btn.setText("Button on Bottom");
    
            v.addView(btn);
            btn.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                }
            });
    
            return v;
        }
    

提交回复
热议问题