Add buttons to PreferenceFragment

后端 未结 4 1988
野性不改
野性不改 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:11

    you may try this

    @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                LinearLayout v = (LinearLayout) super.onCreateView(inflater, container, savedInstanceState);
    
                Button SendLogbtn = new Button(getActivity().getApplicationContext());
                SendLogbtn.setText("send log file");
    
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
    
                params.setMargins(100, 0, 0, 500);
                SendLogbtn.setLayoutParams(params);
    
                v.addView(SendLogbtn);
    
                SendLogbtn.setOnClickListener(new View.OnClickListener() {
    
                    public void onClick(View v) {
    
                        // do your code 
    
                    }
                });
    
                return v;
            }
    

提交回复
热议问题