android学习--开发文档(Training) 01

版权声明:转载标明来源 https://blog.csdn.net/qq_33347077/article/details/82055603

前言#

之前在自己看着一些教程在一定程度上了解了关于android编程的相关知识,但是自己在写一些程序的时候总感觉底子很虚,为此笔者找到SDK中的开发文档,试图继续学习开发文档中的训练部分。以图进一步了解关于android的一些东西。

我会记录一些我觉得有用的内容放在这里,以方便现在的学习和今后的再次查看

Building Your First App

1. create an andriod project/

1.1 app/build.gradle
Android studio使用Gradle来编译和构建我们的APP。每个模块和整个工程都有对应的gradle文件。

1.2 menu/
用于app的menu项目,一般需要自己新建出来

1.3 mipmap/
用来存储发布的icons等资源

1.4 values/
一系列xml文件

2. running your application

2.1在真机上进行运行

真机上需要开启手机的USB调试,一般在手机的开发者选项中,不同的手机进入开发者的方式不一样,根据自己的情况酌情考虑

2.2 在模拟器上运行

笔者按照android studio的引导程序来新建模拟器存在一定的问题。新建的模拟器虽然能够启动android系统,但是并不能进行运行app。后来发现默认创建的模拟器上有一个小锁的按钮,于是就新建了一个没有锁的模拟器,成功解决问题。

3. building a simple user interface

The graphical user interface for an Android app is built using a 
hierarchy of View and ViewGroup objects. 

Layouts are subclasses of the ViewGroup. 

4. starting another activity

4.1 build an intent

An Intent is an object that provides runtime binding between
separate components (such as two activities). The Intent represents 
variety of tasks, but in this lesson, your intent starts another 
activity.

下面是intent启动另外一个应用的用法

Intent intent = new Intent(this, DisplayMessageActivity.class);
startActivity(intent);

intent的第一个参数是context,activity是context的子类。第二个参数是需要跳转的类的class。

//下面这段代码感觉信息挺多的,就从文档中直接粘贴下来
@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_display_message);
    //该方法回调得到传递的intent对象
   Intent intent = getIntent();
   String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
    //动态添加TextView对象
   TextView textView = new TextView(this);
   //设置属性
   textView.setTextSize(40);
   textView.setText(message);
    //获取viewgroup对象
   ViewGroup layout = (ViewGroup) findViewById(R.id.activity_display_message);
   //将texiview对象添加到容器中
   layout.addView(textView);
}

至此完毕

猜你喜欢

转载自blog.csdn.net/qq_33347077/article/details/82055603
今日推荐