Custom preference, targetSdkVersion=“11”: missing indent?

后端 未结 5 1162
既然无缘
既然无缘 2020-12-14 18:49

I have a couple of custom DialogPreference implementations floating around, such as this one:

package apt.tutorial;

import android.content.Cont         


        
5条回答
  •  无人及你
    2020-12-14 19:33

    (cross-posting from the associated android-developers thread)

    OK, I figured it out.

    There are three possible constructors on a Preference:

    MyPreference(Context ctxt)
    MyPreference(Context ctxt, AttributeSet attrs)
    MyPreference(Context ctxt, AttributeSet attrs, int defStyle)
    

    Somewhere along the line, I picked up the pattern of having the one-parameter constructor chain to the two-parameter constructor (passing null for the 2nd parameter), and having the two-parameter constructor chain to the three-parameter constructor (passing 0 for the 3rd parameter).

    And that's not the right answer.

    I am hoping that the right answer is to only implement the second constructor, because the correct default style is internal to Android (com.android.internal.R.attr.dialogPreferenceStyle). The second constructor is the one used with inflating preference XML.

    Thanks to all for the help!

提交回复
热议问题