我在不使用 xml 的情况下创建了一个弹出窗口。我有 4 个按钮,我需要它们处于自定义形状。有人可以给我一个如何做到这一点的例子吗?
这是弹出实现:
public class PopupAudio extends Activity implements OnClickListener {
LinearLayout layoutOfPopup;
PopupWindow popupMessage;
Button popRecord, popStopRecord, popPlay, popStopPlaying;
TextView popupText;
Audio audio;
public PopupAudio(Audio audio) {
this.audio = audio;
}
public void showPopUp(View anchor) {
popupMessage.showAsDropDown(anchor);
}
public void popupInit() {
popRecord.setOnClickListener(this);
popStopRecord.setOnClickListener(this);
popPlay.setOnClickListener(this);
popStopPlaying.setOnClickListener(this);
popupMessage = new PopupWindow(layoutOfPopup, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popupMessage.setContentView(layoutOfPopup);
//popupMessage.setBackgroundDrawable(R.drawable.popup_layout);
}
public void init(Context context) {
popRecord = new Button(context);
popRecord.setId(112);
popStopRecord = new Button(context);
popPlay = new Button(context);
popStopPlaying = new Button(context);
layoutOfPopup = new LinearLayout(context);
popRecord.setText("REC");
layoutOfPopup.setOrientation(1);
layoutOfPopup.addView(popRecord);
layoutOfPopup.addView(popStopRecord);
layoutOfPopup.addView(popPlay);
layoutOfPopup.addView(popStopPlaying);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case 112:
popRecord.setText("STOP");
break;
}
}
}
这是我要使用的形状:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="0dp"
android:topRightRadius="30dp"
android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp" />
<stroke
android:width="3dp"
android:color="@android:color/background_dark" />
<solid
android:color="#800000c0"/>
</shape>