这个类是我在我的应用程序中调用的一个对话框,它工作得很好,它的中心有一个大黑点,这个对话框不需要 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 的情况下添加搜索栏的信息,我们将不胜感激。再见并提前感谢。