2013-12-19 62 views
0

我想更改编号选择器的样式。 这是我的号码选取器enter image description here更改编号选择器样式

我想从数字选取器的上方和下方消失+和 - 符号。可能吗 ?我应该怎么做?

这是我使用的代码:

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

有两种样式数选择器插件可供选择,这取决于你的应用程序的主题。 要获取没有+和 - 按钮的数字选取器,请使用从Theme_Holo或Theme_Holo_Light派生的主题。

+1

我应该在哪里换主题? – user3032822