How to add a button to a PreferenceScreen?

后端 未结 10 1289
抹茶落季
抹茶落季 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:29

    For the xml:

    
    

    Then for the java in your onCreate()

    Preference button = findPreference(getString(R.string.myCoolButton));
    button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) { 
            //code for what you want it to do 
            return true;
        }
    });
    

    This will appear like a normal Preference, with just a title and a summary, so it will look like it belongs.

提交回复
热议问题