4

我想更改 NumberPicker 主题,而不是三值主题(例如:值 10):

9 10 11

我想要加号和减号按钮以及中间的数字 10。

我读到这个: http: //developer.android.com/reference/android/widget/NumberPicker.html 我应该只改变主题,以获得我想要的。但是怎么做?我无法在片段中设置主题:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/gradient_details_bg"
    >

我的片段:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient_details_bg" >

    <Button
        android:id="@+id/buttonGoRandomBlock"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/menu_item_selector"
        android:gravity="center"
        android:text="@string/goButtonText"
        android:textColor="@color/menuItemTextColor"
        android:width="@dimen/menuItemTextSize" />

    <com.testco.selection.NumberPickerCustom
        android:id="@+id/numberPickerCustom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        max="100"
        min="1"
        value="30" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/numberPickerCustom"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp"
        android:gravity="center"
        android:text="@string/randomSelectorText"
        android:textColor="@color/menuItemTextColor"
        android:textSize="@dimen/menuDetailsTextSize" />

</RelativeLayout>

我的片段类:

package com.testco.selection.subfragments;


import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.testco.easytest.R;

public class SubMenuFragment extends Fragment {
    final static String ARG_POSITION = "position";
    int mCurrentPosition = -1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) 
    {

        // If activity recreated (such as from screen rotate), restore
        // the previous article selection set by onSaveInstanceState().
        // This is primarily necessary when in the two-pane layout.
        if (savedInstanceState != null) {
            mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
        }

        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_random_block, container, false);
        return rootView;
    }

    @Override
    public void onStart() {
        super.onStart();

        // During startup, check if there are arguments passed to the fragment.
        // onStart is a good place to do this because the layout has already been
        // applied to the fragment at this point so we can safely call the method
        // below that sets the article text.
        Bundle args = getArguments();
        if (args != null) {
            // Set article based on argument passed in
            updateArticleView(args.getInt(ARG_POSITION));
        } else if (mCurrentPosition != -1) {
            // Set article based on saved instance state defined during onCreateView
            updateArticleView(mCurrentPosition);
        }
    }

    public void updateArticleView(int position) {
//        TextView article = (TextView) getActivity().findViewById(R.id.article);
//        article.setText(Ipsum.Articles[position]);
//        mCurrentPosition = position;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        // Save the current article selection in case we need to recreate the fragment
        outState.putInt(ARG_POSITION, mCurrentPosition);
    }
}
4

1 回答 1

2

从文档

如果当前主题是从小部件派生的,Theme则将当前值显示为可编辑的输入字段,上面有一个递增按钮,下面有一个递减按钮。长按按钮可以快速更改当前值。点击输入字段可以输入所需的值。

所以你需要设置主题。在styles.xml 中定义样式

<style name="cust_dialog" parent="@android:style/Theme.NoTitleBar.Fullscreen" />

要设置主题,请按照大卫的回答@

为片段设置主题

于 2013-09-01T11:14:03.263 回答