根据博主踩的坑,在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之间跳转

更多相关文章

  1. android源码中makefile文件中各参数说明
  2. java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/li
  3. Android7.0解决 android.os.FileUriExposedException: file:///s
  4. Android(安卓)Studio中项目资源出现: Validates resource referen
  5. Linux下使用android ndk编译FFmpeg(最新版FFmpeg 4.4.1)
  6. Android的Button属性使用
  7. Android4.0.3修改启动动画和开机声音
  8. Android面试、笔试、期中/末考试复习提纲总结
  9. android 8.0 自定义控件onmesure获取宽度为0

随机推荐

  1. Android中传感器Sensor的使用
  2. Android事件机制之二:onTouch详解
  3. Android中关于线程使用的几点注意事项
  4. android Intents和Intent Filters - 开发
  5. [Android] 输入法的开发
  6. 【Android手机游戏】贪吃蛇(1)
  7. android 4.0.4系统下实现apk的静默安装和
  8. 【源码分享下载】每日更新之Android项目
  9. Android属性动画,从源码的角度分析
  10. android标题栏的选择与使用,AppCompatActi