Example usage for android.preference EditTextPreference setIcon

List of usage examples for android.preference EditTextPreference setIcon

Introduction

In this page you can find the example usage for android.preference EditTextPreference setIcon.

Prototype

public void setIcon(Drawable icon) 

Source Link

Document

Sets the icon for this Preference with a Drawable.

Usage

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

private void addButtons() {
    // display the "add email" entry
    EditTextPreference addEmailPreference = new EditTextPreference(getActivity());
    addEmailPreference.setTitle(R.string.settings_add_email_address);
    addEmailPreference.setDialogTitle(R.string.settings_add_email_address);
    addEmailPreference.setKey(ADD_EMAIL_PREFERENCE_KEY);
    addEmailPreference.setIcon(CommonActivityUtils.tintDrawable(getActivity(),
            ContextCompat.getDrawable(getActivity(), R.drawable.ic_add_black),
            R.attr.settings_icon_tint_color));
    addEmailPreference.setOrder(100);//from  w ww  . ja  v a  2  s  .com
    addEmailPreference.getEditText()
            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

    addEmailPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String email = (null == newValue) ? null : ((String) newValue).trim();

            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    addEmail(email);
                }
            });

            return false;
        }
    });

    mUserSettingsCategory.addPreference(addEmailPreference);

    // display the "add phone number" entry
    Preference addPhoneNumberPreference = new Preference(getActivity());
    addPhoneNumberPreference.setKey(ADD_PHONE_NUMBER_PREFERENCE_KEY);
    addPhoneNumberPreference.setIcon(CommonActivityUtils.tintDrawable(getActivity(),
            ContextCompat.getDrawable(getActivity(), R.drawable.ic_add_black),
            R.attr.settings_icon_tint_color));
    addPhoneNumberPreference.setTitle(R.string.settings_add_phone_number);
    addPhoneNumberPreference.setOrder(200);

    addPhoneNumberPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = PhoneNumberAdditionActivity.getIntent(getActivity(),
                    mSession.getCredentials().userId);
            startActivityForResult(intent, REQUEST_NEW_PHONE_NUMBER);
            return true;
        }
    });

    mUserSettingsCategory.addPreference(addPhoneNumberPreference);
}