我做了一个暂停按钮,打开一个弹出窗口,其中包含3个按钮,恢复,音乐开/关,重置。
我的问题是按钮在屏幕上,它需要一些地方,它也很丑..我想把这个按钮放在动作栏上......我怎么能这样做?
这是我的按钮:
<Button
android:id="@+id/show_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_alignLeft="@+id/YouLost"
android:layout_alignParentRight="true"
android:background="@drawable/pausesign" />
这是弹出对话框代码:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
int[] location = new int[2];
Button button = (Button) findViewById(R.id.show_popup);
button.getLocationOnScreen(location);
p = new Point();
p.x = location[0];
p.y = location[1]; }
private void showPopup(final Activity context, Point p) {
int popupWidth = 2000;
int popupHeight = 1200;
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
int OFFSET_X = 60;
int OFFSET_Y = 60;
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
Button close = (Button) layout.findViewById(R.id.close);
Button restart = (Button) layout.findViewById(R.id.restart);
final Button music = (Button) layout.findViewById(R.id.music);
musicstop = (Button) layout.findViewById(R.id.musicstop);
musicstop.setVisibility(View.GONE);
music.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPlayer.pause();
musicstop.setVisibility(View.VISIBLE);
music.setVisibility(View.GONE);} });
musicstop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
musicstop.setVisibility(View.GONE);
music.setVisibility(View.VISIBLE);
mPlayer.start(); } });
close.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
popup.dismiss(); } });
restart.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
popup.dismiss();
highscore_int.setText("");
YouLost.setText("Game restarted");
counter=0;
TimeCounter=0;
TimeCounter1=0;
TimeCounter2=0;
TimeCounter3=0;
TimeCounter4=0;
changingTextView.setText(""+counter);
button6.setBackgroundColor(Color.rgb(TimeCounter, TimeCounter, TimeCounter));
button5.setBackgroundColor(Color.rgb(TimeCounter1*2, TimeCounter1*2, TimeCounter1*2));
button4.setBackgroundColor(Color.rgb(TimeCounter2*3, TimeCounter2*3, TimeCounter2*3));
button3.setBackgroundColor(Color.rgb(TimeCounter3*4, TimeCounter3*4, TimeCounter3*4));
button1.setBackgroundColor(Color.rgb(TimeCounter4*5, TimeCounter4*5, TimeCounter4*5));
mPlayer.start();
} });
}
如何将此按钮添加到操作栏?