我想更改NumberPicker主题,而不是三个值主题(例如:value 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);
}
}
答案 0 :(得分:2)
来自文档
如果当前主题派生自Theme
,则窗口小部件将当前值显示为可编辑输入字段,上方带有增量按钮,下方带有减量按钮。长按按钮可以快速更改当前值。点击输入字段可以输入所需的值。
所以你需要设置主题。在styles.xml中定义样式
<style name="cust_dialog" parent="@android:style/Theme.NoTitleBar.Fullscreen" />
要设置主题,请按照David的回答@