ctrl+alt+L 格式化代码
Ctrl+D:复制光标所在行的代码,并在此行的下面粘贴出来。
常见5种界面布局:RalativeLayout、LinearLayout、FrameLayout、TableLayout、ConstrainLayout
布局的通用属性:
android:id
Layout_marginLeft
Layout_marginTop
Layout_marginRight
Layout_marginBottom
1.线性布局LinearLayout属性
orientation:组件的排列方式 horizontal(水平)_vertical(竖直,默认)
layout_gravity:子元素位于父元素的位置
gravity:控件内部的元素位于该控件的位置
【
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#ccccff" android:gravity="right"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button1"/> </LinearLayout> </LinearLayout>
】
layout_width/layout_heigth:布局的宽/高度,通常不直接写数,wrap_content、fill_parent、match_parent
id:在Java文件中可以通过findViewById(id)找到该组件
background:为该组件设置一个背景图片,或者直接用颜色覆盖
divider:为LinearLayout设置分割线的图片
showDividers:设置分割线的位置none、begin、end、middle、
dividerPadding:设置分割线的padding
2.相对布局RalativeLayout属性
layout_above:将该控件的底部置于给定ID的控件之上
layout_below:将该控件的底部置于给定ID的控件之下
layout_toLeftOf:(某元素左边)将该控件的右边缘于给定ID的左边缘对齐
layout_toRightOf:(某元素右边)将该控件的左边缘于给定ID的右边缘对齐
layout_alignBaseline :
layout_alignTop
layout_alignBottom:与某控件的下边界对齐,属性值@id/
layout_alignLeft
layout_align_right
//相对于父组件(属性值true false)
layout_alignParentTop
layout_alignParentBottom:与父控件底端对齐
layout_alignParentRight
layout_alignParentLeft
layout_centerHorizontal:是否水平居中
layout_centerVertical:是否垂直居中
layout_centerInParent:是否位于父空间的中央
//指定移动像素
layout_marginTop
layout_marginBottom
layout_marginLeft
layout_marginRight
2021.9.26.23:26
创建一个普通对话框
【
第一种:
当在new对话框的时候需要通过构造器Builder(this) l来构造,这样我们就创建了对话框的实例。Builder是AlertDialog的内部静态类
new AlertDialog.Builder(this).setTitle("Dialog对话框")//设置标题 .setMessage("是否退出")//设置提示的信息 .setIcon(R.mipmap.ic_launcher) //设置图标 .setPositiveButton("确定",null) .setNegativeButton("取消") .create().show();
第二种:
】
控件的分类
TextView 用来显示文本信息
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HelloWorld"
android:textColor="#000000"
android:textSize="25sp"
android:gravity="center"
/>
EditText 编辑框
EditText继承自TextView。子类继承父类,父类有的子类一定有
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入姓名"
android:maxLength="2"
android:textColor="#000000"//
android:textSize="20sp"
android:textStyle="italic"// bold、normal
/>
Button 按钮 用于响应用户的一系列点击事件
<Button
android:id="@+id/btn"
android:text="按钮"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="click"//设置点击事件
/>
实现点击事件的两种方法
2021.10.03 编译项目时Run窗口中文乱码
help>Edit Custom VM Options>studio64.exe.vmoptions编辑框,添加-Dfile.encoding=UTF-8
重启
RadioButton 单选按钮
ImageView 用来展示图片
Ctrl+~:切换编辑界面的风格,快捷键设计
顶部菜单栏不见了
1.快捷键ctrl+alt+s打开settings面板,选择keymap,2.右键Main menu 选项,选择第一个“add Keyboard Shortcut”,去设置快速开启视图的快捷键,设置第一组快捷键我的快捷键是:ctrl+alt+enter 打开我们设置的快捷键,依次选择View --> Appearance --> Main Menu,顶部菜单栏恢复了
android studio没有欢迎界面
打开settings对话框 找到“Appearance & Behavior” -> “System Settings”,然后在右侧找到”Reopen last project on startup“,记得取消选中
Android中的Intent是一个非常重要且常用的类,可以用来在一个组件中启动App中的另一个组件或者是启动另一个App的组件