0

スピナーをクリックすると表示されるポップアップの背景を変更したい。フォーラムとAndroidソースを調べましたが、何も機能しませんでした。デフォルトのまま、背景は灰色のままです。これまで、アクションバーからのオーバーフローをクリックしたときに表示されるポップアップをカスタマイズして、すべてが想定どおりに機能するようにしましたが、このスピナーウィジェットで問題が発生しています。私が試したところまで:

<style name="AppTheme.Dark" parent="@android:style/Theme.Holo">


<item name="android:spinnerStyle">@style/SpinnerDropDownItem</item>

</style>

    <style name="SpinnerDropDownItem" parent="@android:style/Widget.Spinner">
      <item name="android:popupBackground">@drawable/menu_dropdown_panel_actinonbarstyle</item>
  </style>

ソースで検索したものからのその他の組み合わせ。誰かが私を助けてくれますか、コード例で、私は本当に立ち往生しているので、どうすればこれを行うことができますか?Android4.0以降用のアプリケーションを開発しています。どうも

4

1 に答える 1

4

ここに画像の説明を入力してください

私はこの答えについてよくわかりません、あなたはそれを受け入れるか無視することができます。

この要件は、テーマの変更では不可能だと思います。Spinnerコンストラクターは、レイアウトxmlで記述した場合にのみpopupBackground attrに値を割り当てるため、それ以外の場合はデフォルトのテーマ値を使用します。以下のように:

    <Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:popupBackground="@android:color/holo_green_dark" />

スピナーコンストラクターのソースコードを添付しているので、知識が深まります。

       /**
 * Construct a new spinner with the given context's theme, the supplied attribute set,
 * and default style. <code>mode</code> may be one of {@link #MODE_DIALOG} or
 * {@link #MODE_DROPDOWN} and determines how the user will select choices from the spinner.
 *
 * @param context The Context the view is running in, through which it can
 *        access the current theme, resources, etc.
 * @param attrs The attributes of the XML tag that is inflating the view.
 * @param defStyle The default style to apply to this view. If 0, no style
 *        will be applied (beyond what is included in the theme). This may
 *        either be an attribute resource, whose value will be retrieved
 *        from the current theme, or an explicit style resource.
 * @param mode Constant describing how the user will select choices from the spinner.
 * 
 * @see #MODE_DIALOG
 * @see #MODE_DROPDOWN
 */
public Spinner(Context context, AttributeSet attrs, int defStyle, int mode) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs,
            com.android.internal.R.styleable.Spinner, defStyle, 0);

    if (mode == MODE_THEME) {
        mode = a.getInt(com.android.internal.R.styleable.Spinner_spinnerMode, MODE_DIALOG);
    }

    switch (mode) {
    case MODE_DIALOG: {
        mPopup = new DialogPopup();
        break;
    }

    case MODE_DROPDOWN: {
        DropdownPopup popup = new DropdownPopup(context, attrs, defStyle);

        mDropDownWidth = a.getLayoutDimension(
                com.android.internal.R.styleable.Spinner_dropDownWidth,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        popup.setBackgroundDrawable(a.getDrawable(
                com.android.internal.R.styleable.Spinner_popupBackground));
        final int verticalOffset = a.getDimensionPixelOffset(
                com.android.internal.R.styleable.Spinner_dropDownVerticalOffset, 0);
        if (verticalOffset != 0) {
            popup.setVerticalOffset(verticalOffset);
        }

        final int horizontalOffset = a.getDimensionPixelOffset(
                com.android.internal.R.styleable.Spinner_dropDownHorizontalOffset, 0);
        if (horizontalOffset != 0) {
            popup.setHorizontalOffset(horizontalOffset);
        }

        mPopup = popup;
        break;
    }
    }

    mGravity = a.getInt(com.android.internal.R.styleable.Spinner_gravity, Gravity.CENTER);

    mPopup.setPromptText(a.getString(com.android.internal.R.styleable.Spinner_prompt));

    mDisableChildrenWhenDisabled = a.getBoolean(
            com.android.internal.R.styleable.Spinner_disableChildrenWhenDisabled, false);

    a.recycle();

    // Base constructor can call setAdapter before we initialize mPopup.
    // Finish setting things up if this happened.
    if (mTempAdapter != null) {
        mPopup.setAdapter(mTempAdapter);
        mTempAdapter = null;
    }
}
于 2013-03-26T13:07:39.923 に答える