这个类是我在我的应用程序中调用的对话框,它在中心有一个很大的黑点,这个对话框不需要XML文件。我想在此对话框中添加一个搜索栏,因为我想在滚动搜索栏时更改刚刚提到的点的大小。
public class StrokePicker extends Dialog {
StrokePicker strokepicker;
public StrokePicker(Context context) {
super(context);
}
public class StrokePickerView extends View {
Paint Stroke;
SeekBar seekbar;
private static final int mCENTER= 32;
public StrokePickerView(Context context) {
super(context);
Stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
Stroke.setStyle(Paint.Style.FILL);
Stroke.setColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawCircle(canvas.getWidth()/2-mCENTER, canvas.getHeight()/2-mCENTER*3, mCENTER, Stroke);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(125 * 2, 100 * 2);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(getContext());
SeekBar seekbar;
layout.setOrientation(LinearLayout.VERTICAL);
layout.setGravity(Gravity.CENTER);
layout.setPadding(10, 10, 10, 10);
layout.addView(new StrokePickerView(getContext()),
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
setContentView(layout);
setTitle("Grosor");
}
}
我还没有找到有关如何在不使用XML的情况下添加搜索栏的信息,我们将不胜感激任何帮助。再见,谢谢你。
答案 0 :(得分:1)
或
builder.setView(View v); here is how you can use it.
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();
SeekBar sb = (SeekBar)layout.findViewById(R.id.yourSeekBar);
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
//Do something here with new value
}
});