How to add a button to a PreferenceScreen?

后端 未结 10 1278
抹茶落季
抹茶落季 2020-11-28 20:48

I\'m quite new to Android Development and just came across Preferences. I found PreferenceScreen and wanted to create a login functionality with it. The only pr

10条回答
  •  渐次进展
    2020-11-28 21:39

    Add

    setContentView(R.layout.buttonLayout);
    

    Below

    addPreferencesFromResource(R.xml.yourPreference);
    

    buttonLayout:

    
    
    
    
    
    
    
        

    Access Button by:

    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //Your event
        }
    });
    

    You can get the button on top or on bottom of the screen by putting the button in RelativeLayout:

    • top_control_bar
    • bottom_control_bar

    bottom_control_bar

    This worked for me. I hope I can help someone with this piece of code.

提交回复
热议问题