On my PreferenceScreen, I would like a return button. I found many links about how create a button in a PreferenceScreen. I tried to implement the solution which consists to import a layout in a Preference tag, but the implementation of setOnPreferenceClickListener in my code doesn't work, when I click there's no effect. I used a fragment inside the Preference tag.
PreferenceScreen :
<Preference
android:key="fragment_return_key"
android:layout="@layout/fragment_return"
></Preference>
Fragment:
<RelativeLayout android:id="@+id/lytopnavreturn"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<ImageButton
android:id="@+id/btnfragnavreturn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:src="@drawable/return_32"
android:background="@android:color/transparent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/txtfragnavreturnsettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_settings"
android:textSize="18dp"
android:textStyle="bold"
android:textColor="@color/colorPrimaryDark"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
Activity OnCreate code:
Preference button2 = (Preference)findPreference("fragment_return_key");
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
onBackPressed();
return true;
}
});
The fragment displays, but no event launch on click.
Thanks.