Android数字选择器主题(加上减号按钮) [英] Android numberpicker theme (plus minus buttons)

查看:125
本文介绍了Android数字选择器主题(加上减号按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

9 10 11

我想在中间有加号和减号按钮以及数字10.

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

我读了这篇: http://developer.android.com/reference/android/widget/NumberPicker.html 我应该只更改主题,以获得我想要的. 但是如何?我无法在片段中设置主题:

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

我的片段:

<?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);
    }
}

推荐答案

来自文档

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

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.

因此,您需要设置主题.在styles.xml中定义样式

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

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

要设置主题,请遵循David的回答@

To set the theme follow David's answer @

设置片段的主题

这篇关于Android数字选择器主题(加上减号按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆