I have a custom DialogPreference:
<com.myapp.MyPreferenceDialog
android:key="dialog_key"
android:title="Test MyDialogPreference"
android:positiveButtonText="ok"
android:negativeButtonText="cancel"
/>
The dialog code is the following:
class MyDialogPreference extends DialogPreference
{
public MyDialogPreference( Context context, AttributeSet attrs )
{
super(context, attrs);
setDialogLayoutResource( R.layout.test );
}
}
The layout xml code is the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/image" />
</LinearLayout>
When i launch the app settings and touch "Test MyDialogPreference", a dialog is shown but the imageview does not display any image. I know how to fix this programmatically (just override onBindDialogView()
and set the ImageView image resource to its drawable), but i would like to understand why i have to do it programmatically.
add following to your build.gradle file
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.