Android 例子 对话框弹出效果

版权声明:本博所有原创文章,欢迎转载但不得作为商业用途,转载请注明出处。 https://blog.csdn.net/qq_16587307/article/details/86292638
package com.example.new1;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.util.TypedValue;
import android.graphics.Color;
import android.util.Log;

public class kkActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_kk);
        FrameLayout frameLayout = new FrameLayout(this);
        frameLayout.setBackgroundResource(R.mipmap.timg);
        setContentView(frameLayout);
        TextView text1 = new TextView(this);
        text1.setText("开始游戏");
        text1.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
        text1.setTextColor(Color.rgb(17,85,114));
        FrameLayout.LayoutParams params=new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity=Gravity.CENTER;
        text1.setLayoutParams(params);
        text1.setOnClickListener(new View.OnClickListener(){
            @Override
                    public void onClick(View v){
                new AlertDialog.Builder(kkActivity.this).setTitle("系统提示")
                        .setMessage("游戏有风险,进入需谨慎,真的要进入吗?")
                        .setPositiveButton("确定",
                                new DialogInterface.OnClickListener() {
                            @Override
                                    public void onClick(DialogInterface dialog, int which){
                                Log.i("桌面台球","进入游戏");
                            }
                                }).setNegativeButton("退出", new DialogInterface.OnClickListener(){
                                    @Override
                    public void onClick(DialogInterface dialog, int which){
                                        Log.i("桌面台球","退出游戏");
                                        finish();
                                    }
                }).show();
            }
        });
        frameLayout.addView(text1);
    }
}

效果如下:

猜你喜欢

转载自blog.csdn.net/qq_16587307/article/details/86292638