zoukankan      html  css  js  c++  java
  • 在java代码中控制UI界面

    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            //setContentView(R.layout.activity_main);
            FrameLayout frameLayout=new FrameLayout(this);
            frameLayout.setBackgroundResource(R.mipmap.bg);
            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(MainActivity.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);
        }
    }
  • 相关阅读:
    宏定义抽取单例
    谓词基本使用
    Xcode静态分析工具--Analyze
    [转载]CocoaPods管理第三方开源框架
    @import--iOS7新关键字
    iOS手势识别
    UINavigationController
    JSON解析--原生&AFN
    UITabBarController
    iOS APP EuclidStudy Service Support
  • 原文地址:https://www.cnblogs.com/junjunjun123/p/9978196.html
Copyright © 2011-2022 走看看