我搞砸了一些东西,最后一无所获。有人可以向我展示一个非常基本的示例,如何使用路径显示带有边框轮廓的弹出窗口。请不要发布 XML 形状。我需要使用路径,因为轮廓不会是矩形的。
我有一些 poc 工作,但后来我完全搞砸了一些东西,现在什么都没有。
基本上我所拥有的是(不完整的代码):
public myPop extends PopupWindow {
public myPop(Conext context) {
super(context);
setFocusable(true);
setWindowLayoutMode(View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.AT_MOST), ViewGroup.LayoutParams.WRAP_CONTENT);
LayoutInflater inflater = LayoutInflater.from(context);
layout = inflater.inflate(R.layout.settings2, null);
//setBackgroundDrawable(new ColorDrawable(Color.BLUE));
Path path = new Path();
path.moveTo(0, 0);
path.lineTo(100, 0);
path.lineTo(100, 100);
setBackgroundDrawable(new OutlineDrawable(path);
setContentView(layout);
}
public void show() {
showAtLocation(this.parent, Gravity.NO_GRAVITY, 100, 500);
}
}
OutlineDrawable 只不过是在 draw() 中扩展 Drawable ,我用给定的路径调用 drawPath() 和一些带有描边样式的绘画。