开发者

How to add an ImageView inside a PreferenceActivity?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜