我想更改数字Picker的样式。 这是我的号码选择器
我想从数字选择器的上方和下方消失+和 - 符号。可能吗 ?我该怎么做?
这是我使用的代码:
public class MainActivity extends Activity implements OnClickListener {
EditText etSearch;
int mStackLevel = 1;
Button btn, btnSearch, btnCancel;
Dialog dialog;
NumberPicker np;
final String[] values_data = {"Belgium", "France", "United Kingdom"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FrameLayout f = (FrameLayout)findViewById(R.id.simple_fragment);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener((OnClickListener) this);
}
protected void showCustomDialog() {
btn.setEnabled(false);
dialog = new Dialog(MainActivity.this,
android.R.style.Theme_Translucent);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.dialog);
np = (NumberPicker) dialog.findViewById(R.id.numberPicker1);
np.setMaxValue(2);
np.setMinValue(0);
Log.i(null, "State three");
np.setDisplayedValues(values_data);
Log.i(null, "State four");
np.setWrapSelectorWheel(false);
btnSearch = (Button) dialog.findViewById(R.id.btnsearch);
btnCancel = (Button) dialog.findViewById(R.id.btncancel);
btnSearch.setOnClickListener(this);
btnCancel.setOnClickListener(this);
dialog.show();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn:
btn.setEnabled(true);
showCustomDialog();
break;
case R.id.btnsearch:
//btn.setVisibility(View.VISIBLE);
Log.i(String.valueOf(np.getValue()), "HHHHHHH");
int value = (np.getValue());
Log.i(String.valueOf(value), "MSGGGGGGGGGG");
btn.setText(String.valueOf(values_data[value]));
dialog.dismiss();
break;
case R.id.btncancel:
dialog.dismiss();
break;
default:
break;
}
}
public static class CountingFragment extends Fragment {
int mNum;
static CountingFragment newInstance(int num) {
CountingFragment f = new CountingFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
}
/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}*/
}
答案 0 :(得分:0)
有两种样式的数字选择器小部件可用,它取决于您的应用程序主题。 要获得不带+和 - 按钮的数字选择器,请使用从Theme_Holo或Theme_Holo_Light派生的主题。