質問

I would like to change the NumberPicker theme, instead of the three value theme (eg: value 10):

9 10 11

I would like to have the plus and the minus button and the numer 10 in the middle.

I read this: http://developer.android.com/reference/android/widget/NumberPicker.html I should change only the theme, to obtain what I wish. But how? I can't set the theme in my fragment:

<?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"
    >

My fragment:

<?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>

My fragment class:

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);
    }
}
役に立ちましたか?

解決

From the docs

If the current theme is derived from Theme the widget presents the current value as an editable input field with an increment button above and a decrement button below. Long pressing the buttons allows for a quick change of the current value. Tapping on the input field allows to type in a desired value.

So you will need to set the theme. Define styles in styles.xml

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

To set the theme follow David's answer @

Set theme for a Fragment

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top