1.创建活动:
活动(Activity)是最容易吸引用户的地方,它是一种可以包含用户界面的组件,主要用于和用户进行交互。一个应用程序中可以包含零个或多个活动
右击com.example.activitytest包→New→Activity→Empty Activity,会d出一个创建活动的对话框,我们将活动命名为FirstActivity,并且不要勾选Generate file和Launcher Activity这两个选项,
public class FirstActivity extends AppCompatActivity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentVIEw(R.layout.first_layout);
}
}
2.创建布局
AndroID程序的设计讲究逻辑和视图分离,最好每一个活动都能对应一个布局,布局就是用来显示界面内容的,因此我们现在就来手动创建一个布局文件。 右击app/src/main/res目录→New→Directory,会d出一个新建目录的窗口,这里先创建一个名为layout的目录。然后对着layout目录右键→New→Layout resource file,又会d出一个新建布局资源文件的窗口,我们将这个布局文件命名为first_layout
3.为活动设置布局
setContentVIEw(R.layout.first_layout);
4.注册活动
所有的活动都要在AndroIDManifest.xml中进行注册才能生效
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.example.activitytest"> <application androID:allowBackup="true" androID:icon="@mipmap/ic_launcher" androID:label="@string/app_name" androID:roundIcon="@mipmap/ic_launcher_round" androID:supportsRtl="true" androID:theme="@style/Apptheme"> <activity androID:name=".FirstActivity" androID:label="@string/app_name"> <intent-filter> <action androID:name="androID.intent.action.MAIN"></action> <category androID:name="androID.intent.category.LAUNCHER"></category> </intent-filter> </activity> </application></manifest>
总结
以上是内存溢出为你收集整理的2.Android开发:Activity全部内容,希望文章能够帮你解决2.Android开发:Activity所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)