• 安卓app_sl3.2弹出消息对话框


    package com.example.sl3_2a;
    
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.util.Log;
    import android.util.TypedValue;
    import android.view.Gravity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    
    import android.widget.FrameLayout;
    import android.widget.FrameLayout.LayoutParams;
    import android.widget.TextView;
    
    
    
    
    
    public class MainActivity extends Activity {
    
        public TextView text2;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            //setContentView(R.layout.activity_main);
            FrameLayout frameLayout=new FrameLayout(this);
            frameLayout.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.background));
            setContentView(frameLayout);
            TextView text1=new TextView(this);
            text1.setText("在代码中控制UI界面");
            text1.setTextSize(TypedValue.COMPLEX_UNIT_PX,24);
            text1.setTextColor(Color.rgb(1, 1, 1));
            frameLayout.addView(text1);
            
            text2=new TextView(this);
            text2.setText("单击进入游戏。。。");
            text2.setTextSize(TypedValue.COMPLEX_UNIT_PX,50);
            text2.setTextColor(Color.rgb(1, 1, 1));
          //  LayoutParams params=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                //    ViewGroup.LayoutParams.WRAP_CONTENT);
         //   params.gravity=Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL;
            LayoutParams params = new LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT); // 创建保存布局参数的对象
            params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
            text2.setLayoutParams(params);
            text2.setOnClickListener(new OnClickListener()
                    {
                       @Override
                       public void onClick(View v)
                       {
                           new AlertDialog.Builder(MainActivity.this).setTitle("系统提示")
                           .setMessage("游戏有风险,进入需谨慎,确认进入吗?")
                           .setPositiveButton("确定", new DialogInterface.OnClickListener() 
                           {
                            
                            @Override
                            public void onClick(DialogInterface dialog, int which) 
                            {
                                Log.i("3.2","进入游戏");
                                // TODO 自动生成的方法存根
                                
                            }
                           }).setNegativeButton("退出", new DialogInterface.OnClickListener() {
                            
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // TODO 自动生成的方法存根
                                Log.i("3.2","退出游戏");
                                
                            }
                        
                        }).show();
                       }
                    });
            
            frameLayout.addView(text2);                // 将text2添加到布局管理器中
            
            
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    }

  • 相关阅读:
    Notepad++ 6.2.3 发布,开源文本编辑器
    Scrum项目如何获得管理层的支持和合作
    Concurrency Kit 0.2.13 发布,并发工具包
    Orubase:为Windows Phone、Android和iOS平台开发混合本地手机应用程序
    CyaSSL 2.4.6 发布,SSL 加密库
    谷歌移动应用强调设计元素:向极简风格转型
    Bitcoin 0.7.2 发布, 匿名数字货币
    Netty 3.5.11 发布
    LDAP Account Manager 4.0 发布
    Apache Commons Math 3.1 发布
  • 原文地址:https://www.cnblogs.com/txwtech/p/15880742.html
Copyright © 2020-2023  润新知