开发者

How to add an ImageView inside a PreferenceActivity?

开发者 https://www.devze.com 2023-04-11 08:55 出处:网络
His is my preference activity: <?xml version=\"1.0\" encoding=\"utf-8\"?> <PreferenceScreen xmlns:android=\"http://schemas.android.com/apk/res/android\">

His is my preference activity:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android">


       <PreferenceCategory
            android:title="Select your country or region">
                <ListPreference
                android:title="Pick your country"
                android:key="regionsListPref"
                android:defaultValue="digiGreen"
                android:entries="@array/regionArray"
                android:entryValues="@array/regionValues" />

                <ImageView  
         android:id="@+id/ImageView01"  
         android:layout_height="fill_parent"  
         android:layout_width="fill_parent"  
         android:cropToPadding="true"  
         android:adjustViewBounds="true"
         android:src="@drawable/splash"
         android:scaleType="centerInside"></ImageView> 

        </PreferenceCategory>

    <PreferenceCategor开发者_Python百科y
            android:title="Second Category">
      <CheckBoxPreference android:title="@string/bjr" android:key="macheckbox"
      android:summaryOn="La checkbox est cochée"
      android:summaryOff="La checkbox n'est plus cochée"
      android:defaultValue="true"
       />

      <EditTextPreference android:title="Mon EditText"
      android:dialogTitle="Modification du texte"
      android:dialogMessage="Entrez le nouveau texte"
      android:dialogIcon="@drawable/icon" 
      android:defaultValue="Texte par défaut" android:key="montextedit"/>
       </PreferenceCategory>

</PreferenceScreen>

With mmy code there is no error when building the project. But I got an exception when running it by displaying the preference activity.

So, my question is: How to simply add an ImageView into PreferenceActivity?

Best regards


There is no simple way to do that. Your preference activity expects a Preference or a class which extends it so it crashes on other classes which you give.

I never did that before but here's what I would try:

  • Put an default Preference into your settings XML
  • Create a custom layout for the resource (with your image in it)
  • Use android:layout attribute to set you custom layout in settings XML

There might be some traps while setting your custom layout on the preference- Please read setLayoutResource. You can take a look at how the default layout is made up.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号