Android: How to remove arrow down icon next to Edi

2019-06-08 01:44发布

The preference activity gets inflated by invoking

addPreferencesFromResource(R.xml.preferences);

and here are the preferences.xml:

<PreferenceCategory android:title="@string/pref_categ_update_label">
    <ListPreference android:title="@string/pref_label"
        android:key="update_interval" 
        android:entries="@array/update_names" android:entryValues="@array/update_values" />


</PreferenceCategory>


<PreferenceCategory android:title="@string/pref_categ_evernote_label">

    <EditTextPreference android:title="@string/pref_dialog_edit_username"
        android:key="prefUsername" 
        android:positiveButtonText="@string/save_pref"
        android:negativeButtonText="@string/cancel_pref"  />

    <EditTextPreference android:title="@string/pref_dialog_edit_password"
        android:key="prefPassword"  
        android:positiveButtonText="@string/save_pref"
        android:negativeButtonText="@string/cancel_pref"             
        android:password="true" />

</PreferenceCategory>

everything looks okay, but EditTextPreference entries (2 and 3) have arrow-down icons next to them, just like ListPreference (1) does. Why is it so and how can I remove these icons as they look irrelevant?

The screenshot is here: http://i.stack.imgur.com/BZUr7.png

4条回答
家丑人穷心不美
2楼-- · 2019-06-08 01:59

If you dont want the arrows in preferences then use -

**android:widgetLayout="@null"**

And if you want to give some custom image in preference right hand side then use -

**android:widgetLayout="@layout/pref_custom_image"**

where, pref_custom_image.xml will look like -

<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
查看更多
SAY GOODBYE
3楼-- · 2019-06-08 01:59

The arrows are there to let you know that clicking on that preference is going to take you somewhere else. In the case of the ListPreference it indicates that it goes to another "screen" in the case of the EditTextPreference it indicated that it is going to pop up a dialog. If yo don't like it you can create a new style for it and use that instead.

查看更多
相关推荐>>
4楼-- · 2019-06-08 02:04

I'm not 100% sure if this is safe and good way, but you can remove the icon if you extend the EditTextPreference class like that:

By overiding the getView() method you can change what is drawn in the list. I'm using the original view and search it for all images (recursivly) and changing their visibility to GONE.

public class EditTextPreferenceNoImage extends EditTextPreference {
public EditTextPreferenceNoImage(Context context, AttributeSet attrs,
        int defStyle) {
    super(context, attrs, defStyle);
}

public EditTextPreferenceNoImage(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public EditTextPreferenceNoImage(Context context) {
    super(context);
}

@Override
public View getView(View convertView, ViewGroup parent) {
    View view = super.getView(convertView, parent);
    changeImagesVisibility(view, View.GONE);
    return view;
}

private void changeImagesVisibility(View view, int visibility) {
    log.debug("child:" + view.getClass());
    if (view instanceof ViewGroup) {
        ViewGroup ll = (ViewGroup) view;
        for (int i = 0; i < ll.getChildCount(); i++) {
            changeImagesVisibilitz(ll.getChildAt(i), visibility);
        }
    } else if (view instanceof ImageView) {
        log.debug("visiblitz : " + (visibility == View.VISIBLE));
        ImageView image = (ImageView) view;
        image.setVisibility(visibility);
    }

}}
查看更多
啃猪蹄的小仙女
5楼-- · 2019-06-08 02:11

If anyone is having this same issue, I've found a super simple solution to get rid of the arrow on preference items (technically, it gets rid of anything that would appear there--arrow image checkbox, etc.). In your preferences.xml, set the value for Widget Layout to "@null".

查看更多
登录 后发表回答