Custom preference not clickable

烂漫一生 提交于 2019-12-05 04:56:26

问题


I added a custom preference to my project (code below). I added it to my preferences xml with a custom widgetLayout:

<w.PlusOnePreference 
    android:title="Rate App"
    android:key="custom"
    android:widgetLayout="@layout/plusone_pref"/>

Preference layout xml:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.plus.PlusOneButton    
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
plus:size="standard" />

I see the layout and the button in the layout works fine. The only problem is that the preference isn't clickable. Like it's hidden behind something.

Any ideas on how to make it clickable?

If I add a regular Preference (without a widget layout) it works fine.

Thanks.

public class PlusOnePreference extends Preference {

private PlusClient mPlusClient = null; 

public PlusOnePreference(Context context) {
    super(context);

}


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

public PlusOnePreference(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public void setPlusClient(PlusClient plusClient) {
    mPlusClient = plusClient;
}



@Override
protected void onBindView(View view) {
    super.onBindView(view);     
    //mPlusOneButton = 
    PlusOneButton plusOneButton = (PlusOneButton)view.findViewById(R.id.plus_one_button);
    plusOneButton.initialize(mPlusClient, SettingsActivity.URL, SettingsActivity.PLUS_ONE_REQUEST_CODE);
}
  }

回答1:


in layout/plusone_pref.xml set android:focusable="false" for your Button




回答2:


Putting Pskink's answer together with Ran's comment:

  • If your custom preference's layout is a ViewGroup (e.g. a *Layout), use android:descendantFocusability="blocksDescendants"
  • If it's just one View, use android:focusable="false"



回答3:


Preferences don't have a clickable attribute, though there is an onClick() method. Tryandroid:selectable.



来源:https://stackoverflow.com/questions/17243284/custom-preference-not-clickable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!