Android(安卓)Studio 新建页面和跳转
16lz
2021-01-26
根据博主踩的坑,在Android Studio中新建页面有一些讲究的,不是有一个.xml和.java文件就可以了。
步骤:右键->new->Activity->Empty Activity->输入名字->finish。就可以自动生成一个.java文件和一个.xml文件了。
坑: 博主曾经选中layout文件夹,右键->new->选择layout resource file来建.xml文件,选中com.example.mainapp右键->new->Java Class来建立.java文件。这样会出现问题: 明明在.xml文件中添加了很多控件,程序运行起来之后,跳转到这个页面,除了标题和背景图片可以显示,其他的控件都显示不了。
博主改新activity命名为MainActivity3,自动生成了这2个文件:
定义页面样式
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity3"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/backgroup"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textColor="@color/colorAccent" android:text="新页面,新页面\n新页面,新页面"/> </RelativeLayout></androidx.constraintlayout.widget.ConstraintLayout>
页面跳转
可参考另外一篇博客:Android Activity之间跳转
更多相关文章
- android源码中makefile文件中各参数说明
- java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/li
- Android7.0解决 android.os.FileUriExposedException: file:///s
- Android(安卓)Studio中项目资源出现: Validates resource referen
- Linux下使用android ndk编译FFmpeg(最新版FFmpeg 4.4.1)
- Android的Button属性使用
- Android4.0.3修改启动动画和开机声音
- Android面试、笔试、期中/末考试复习提纲总结
- android 8.0 自定义控件onmesure获取宽度为0