-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAngular-Basics.html
1 lines (1 loc) · 91 KB
/
Angular-Basics.html
1
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 5.4.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/favicon-32x32.png"><link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png"><link rel="mask-icon" href="/images/favicon-32x32.png" color="#222"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/jquery.fancybox.min.css" integrity="sha256-Vzbj7sDDS/woiFS3uNKo8eIuni59rjyNGtXfstRzStA=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/nprogress.css" integrity="sha256-no0c5ccDODBwp+9hSmV5VvPpKwHCpbVzXHexIkupM6U=" crossorigin="anonymous"><script src="https://cdn.jsdelivr.net/npm/[email protected]/nprogress.js" integrity="sha256-a5YRB27CcBwBFcT5EF/f3E4vzIqyHrSR878nseNYw64=" crossorigin="anonymous"></script><script class="next-config" data-name="main" type="application/json">{"hostname":"www.wrysmile.cn","root":"/","images":"/images","scheme":"Gemini","version":"8.5.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":true,"color":"#222","save":"manual"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果:${query}","hits_time":"找到 ${hits} 个搜索结果(用时 ${time} 毫秒)","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script><meta name="description" content="本篇是 Android 开发中需要掌握的基础内容"><meta property="og:type" content="article"><meta property="og:title" content="学习笔记:Android"><meta property="og:url" content="https://www.wrysmile.cn/Angular-Basics.html"><meta property="og:site_name" content="Wrysmile 的博客"><meta property="og:description" content="本篇是 Android 开发中需要掌握的基础内容"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://s3.ax1x.com/2020/11/16/DAw0aT.png"><meta property="og:image" content="https://s1.ax1x.com/2020/10/20/0zbYFJ.png"><meta property="og:image" content="https://s3.ax1x.com/2020/12/14/rnIKnx.png"><meta property="og:image" content="https://s3.ax1x.com/2020/12/14/rnIY3d.png"><meta property="og:image" content="https://s3.ax1x.com/2020/12/14/rnIBE8.png"><meta property="og:image" content="https://s3.ax1x.com/2020/12/14/rnIfbV.png"><meta property="og:image" content="https://s3.ax1x.com/2020/12/14/rnI78J.png"><meta property="article:published_time" content="2020-08-31T00:26:24.000Z"><meta property="article:modified_time" content="2023-01-31T10:23:56.186Z"><meta property="article:author" content="Zhang Yangeng"><meta property="article:tag" content="Android"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://s3.ax1x.com/2020/11/16/DAw0aT.png"><link rel="canonical" href="https://www.wrysmile.cn/Angular-Basics.html"><script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://www.wrysmile.cn/Angular-Basics.html","path":"Angular-Basics.html","title":"学习笔记:Android"}</script><script class="next-config" data-name="calendar" type="application/json">""</script><title>学习笔记:Android | Wrysmile 的博客</title><script>!function(e,t,o,c,i,a,n){e.DaoVoiceObject=i,e[i]=e[i]||function(){(e[i].q=e[i].q||[]).push(arguments)},e[i].l=+new Date,a=t.createElement(o),n=t.getElementsByTagName(o)[0],a.async=1,a.src=c,a.charset="utf-8",n.parentNode.insertBefore(a,n)}(window,document,"script",("https:"==document.location.protocol?"https:":"http:")+"//widget.daovoice.io/widget/13e39436.js","daovoice"),daovoice("init",{app_id:"13e39436"}),daovoice("update")</script><noscript><link rel="stylesheet" href="/css/noscript.css"></noscript><link rel="alternate" href="/atom.xml" title="Wrysmile 的博客" type="application/atom+xml"></head><body itemscope itemtype="http://schema.org/WebPage" class="use-motion"><div class="headband"></div><main class="main"><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏" role="button"><span class="toggle-line"></span> <span class="toggle-line"></span> <span class="toggle-line"></span></div></div><div class="site-meta"><a href="/" class="brand" rel="start"><i class="logo-line"></i><h1 class="site-title">Wrysmile 的博客</h1><i class="logo-line"></i></a><p class="site-subtitle" itemprop="description">欢迎来到我的个人小屋</p><img class="custom-logo-image" src="/images/favicon-32x32.png" alt="Wrysmile 的博客"></div><div class="site-nav-right"><div class="toggle popup-trigger"><i class="fa fa-search fa-fw fa-lg"></i></div></div></div><nav class="site-nav"><ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索</a></li></ul></nav><div class="search-pop-overlay"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"><input autocomplete="off" autocapitalize="off" maxlength="80" placeholder="搜索..." spellcheck="false" type="search" class="search-input"></div><span class="popup-btn-close" role="button"><i class="fa fa-times-circle"></i></span></div><div class="search-result-container no-result"><div class="search-result-icon"><i class="fa fa-spinner fa-pulse fa-5x"></i></div></div></div></div></div><div class="toggle sidebar-toggle" role="button"><span class="toggle-line"></span> <span class="toggle-line"></span> <span class="toggle-line"></span></div><aside class="sidebar"><div class="sidebar-inner sidebar-nav-active sidebar-toc-active"><ul class="sidebar-nav"><li class="sidebar-nav-toc">文章目录</li><li class="sidebar-nav-overview">站点概览</li></ul><div class="sidebar-panel-container"><div class="post-toc-wrap sidebar-panel"><div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-text">一、前言</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%BC%80%E5%8F%91%E6%96%B9%E5%90%91"><span class="nav-text">1.开发方向</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E4%BC%A0%E7%BB%9FWindows%E5%BC%80%E5%8F%91"><span class="nav-text">(1).传统Windows开发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E7%A7%BB%E5%8A%A8%E5%BC%80%E5%8F%91"><span class="nav-text">(2).移动开发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-Web%E5%BC%80%E5%8F%91"><span class="nav-text">(3).Web开发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91"><span class="nav-text">(4).嵌入式开发</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%AD%A6%E4%B9%A0%E5%86%85%E5%AE%B9"><span class="nav-text">2.学习内容</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-text">二、基础内容</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E9%9B%B6%E7%A2%8E"><span class="nav-text">1.零碎</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="nav-text">2.环境搭建</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-ADT"><span class="nav-text">(1).ADT</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-Android-Studio"><span class="nav-text">(2).Android Studio</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%97%A5%E5%BF%97%E5%B7%A5%E5%85%B7"><span class="nav-text">3.日志工具</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-text">三、活动(Activity)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%9F%BA%E7%A1%80"><span class="nav-text">1.基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E7%AE%80%E5%8D%95%E7%BC%96%E5%86%99"><span class="nav-text">2.简单编写</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E5%88%9B%E5%BB%BA%E6%B4%BB%E5%8A%A8"><span class="nav-text">(1).创建活动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E5%88%9B%E5%BB%BA%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6"><span class="nav-text">(2).创建布局文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E8%AE%BE%E8%AE%A1%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6"><span class="nav-text">(3).设计布局文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E5%8A%A0%E8%BD%BD%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6"><span class="nav-text">(4).加载布局文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-%E6%B3%A8%E5%86%8C%E6%B4%BB%E5%8A%A8"><span class="nav-text">(5).注册活动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-%E9%85%8D%E7%BD%AE%E4%B8%BB%E6%B4%BB%E5%8A%A8"><span class="nav-text">(6).配置主活动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-%E9%94%80%E6%AF%81%E6%B4%BB%E5%8A%A8"><span class="nav-text">(7).销毁活动</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-Toast"><span class="nav-text">3.Toast</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-Menu"><span class="nav-text">4.Menu</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-Intent"><span class="nav-text">5.Intent</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="nav-text">6.生命周期</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E5%90%AF%E5%8A%A8%E6%A8%A1%E5%BC%8F"><span class="nav-text">7.启动模式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-standard"><span class="nav-text">(1).standard</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-singleTop"><span class="nav-text">(2).singleTop</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-singleTask"><span class="nav-text">(3).singleTask</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-singleInstance"><span class="nav-text">(4).singleInstance</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-%E6%B4%BB%E5%8A%A8%E7%9A%84%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5"><span class="nav-text">8.活动的最佳实践</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E7%9F%A5%E6%99%93%E5%BD%93%E5%89%8D%E5%9C%A8%E5%93%AA%E4%B8%80%E4%B8%AA%E6%B4%BB%E5%8A%A8"><span class="nav-text">(1).知晓当前在哪一个活动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E9%9A%8F%E6%97%B6%E9%9A%8F%E5%9C%B0%E9%80%80%E5%87%BA%E7%A8%8B%E5%BA%8F"><span class="nav-text">(2).随时随地退出程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%90%AF%E5%8A%A8%E6%B4%BB%E5%8A%A8%E7%9A%84%E6%9C%80%E4%BD%B3%E5%86%99%E6%B3%95"><span class="nav-text">(3).启动活动的最佳写法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-text">四、UI 设计</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%A7%86%E5%9B%BE%EF%BC%88View%EF%BC%89"><span class="nav-text">1.视图(View)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%A7%86%E5%9B%BE%E4%B9%8B%E8%A7%86%E5%9B%BE%E7%B1%BB"><span class="nav-text">2.视图之视图类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-TextView"><span class="nav-text">(1).TextView</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-Button"><span class="nav-text">(2).Button</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-EditText"><span class="nav-text">(3).EditText</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-ImageView"><span class="nav-text">(4).ImageView</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-ProgressBar"><span class="nav-text">(5).ProgressBar</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-AlertDialog"><span class="nav-text">(6).AlertDialog</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-ProgressDialog"><span class="nav-text">(7).ProgressDialog</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-%E7%9B%B8%E5%85%B3%E5%B1%9E%E6%80%A7"><span class="nav-text">(8).相关属性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#a-android-id-%E5%B1%9E%E6%80%A7"><span class="nav-text">a).android:id 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#b-android-background-%E5%B1%9E%E6%80%A7"><span class="nav-text">b).android:background 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#c-android-padding-%E5%B1%9E%E6%80%A7"><span class="nav-text">c).android:padding 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#d-android-gravity-%E5%B1%9E%E6%80%A7"><span class="nav-text">d).android:gravity 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#e-android-textSize-%E5%B1%9E%E6%80%A7"><span class="nav-text">e).android:textSize 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#f-android-hint-%E5%B1%9E%E6%80%A7"><span class="nav-text">f).android:hint 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#g-android-maxLines-%E5%B1%9E%E6%80%A7"><span class="nav-text">g).android:maxLines 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#h-android-visibility-%E5%B1%9E%E6%80%A7"><span class="nav-text">h).android:visibility 属性</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E8%A7%86%E5%9B%BE%E4%B9%8B%E5%B8%83%E5%B1%80"><span class="nav-text">3.视图之布局</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E7%BA%BF%E6%80%A7%E5%B8%83%E5%B1%80%EF%BC%88LinearLayout%EF%BC%89"><span class="nav-text">(1).线性布局(LinearLayout)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E7%9B%B8%E5%AF%B9%E5%B8%83%E5%B1%80%EF%BC%88RelativeLayout%EF%BC%89"><span class="nav-text">(2).相对布局(RelativeLayout)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%B8%A7%E5%B8%83%E5%B1%80%EF%BC%88FrameLayout%EF%BC%89"><span class="nav-text">(3).帧布局(FrameLayout)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E7%99%BE%E5%88%86%E6%AF%94%E5%B8%83%E5%B1%80"><span class="nav-text">(4).百分比布局</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-%E7%9B%B8%E5%85%B3%E5%B1%9E%E6%80%A7"><span class="nav-text">(5).相关属性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#a-android-layout-gravity-%E5%B1%9E%E6%80%A7"><span class="nav-text">a).android:layout_gravity 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#b-android-layout-weight-%E5%B1%9E%E6%80%A7"><span class="nav-text">b).android:layout_weight 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#c-android-layout-alignParentXxx-%E5%B1%9E%E6%80%A7"><span class="nav-text">c).android:layout_alignParentXxx 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#d-android-layout-centerInParent-%E5%B1%9E%E6%80%A7"><span class="nav-text">d).android:layout_centerInParent 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#e-android-layout-above-below-%E5%B1%9E%E6%80%A7"><span class="nav-text">e).android:layout_above/below 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#f-android-layout-toLeftOf-toRightOf-%E5%B1%9E%E6%80%A7"><span class="nav-text">f).android:layout_toLeftOf/toRightOf 属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#g-android-layout-alignXXX-%E5%B1%9E%E6%80%A7"><span class="nav-text">g).android:layout_alignXXX 属性</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-%E5%BC%95%E5%85%A5%E5%B8%83%E5%B1%80%E6%88%96%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6"><span class="nav-text">(6).引入布局或自定义控件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#a-%E5%BC%95%E5%85%A5%E5%B8%83%E5%B1%80"><span class="nav-text">a).引入布局</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#b-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6"><span class="nav-text">b).自定义控件</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E8%A7%86%E5%9B%BE%E4%B9%8B%E8%A7%86%E5%9B%BE%E5%AE%B9%E5%99%A8%E7%B1%BB"><span class="nav-text">4.视图之视图容器类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-ListView"><span class="nav-text">(1).ListView</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#b-%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6"><span class="nav-text">b).点击事件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-RecyclerView"><span class="nav-text">(2).RecyclerView</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#a-%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6"><span class="nav-text">a).点击事件</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%88%B6%E4%BD%9C-Nine-Patch-%E5%9B%BE%E7%89%87"><span class="nav-text">5.制作 Nine-Patch 图片</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-ViewGroup-%E7%B1%BB"><span class="nav-text">2.ViewGroup 类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-ViewGroup-LayoutParams-%E7%B1%BB"><span class="nav-text">(1).ViewGroup.LayoutParams 类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-ViewGroup-MarginLayoutParams-%E7%B1%BB"><span class="nav-text">(2).ViewGroup.MarginLayoutParams 类</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-UI%E7%BB%84%E4%BB%B6%E7%9A%84%E5%B1%82%E6%AC%A1%E7%BB%93%E6%9E%84"><span class="nav-text">3.UI组件的层次结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%8E%A7%E5%88%B6UI%E7%95%8C%E9%9D%A2%E7%9A%84%E6%96%B9%E6%B3%95"><span class="nav-text">4.控制UI界面的方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E4%BD%BF%E7%94%A8XML%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6%E6%8E%A7%E5%88%B6UI%E7%95%8C%E9%9D%A2"><span class="nav-text">(1).使用XML布局文件控制UI界面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E5%9C%A8Java%E4%BB%A3%E7%A0%81%E4%B8%AD%E6%8E%A7%E5%88%B6UI%E7%95%8C%E9%9D%A2"><span class="nav-text">(2).在Java代码中控制UI界面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E4%BD%BF%E7%94%A8XML%E5%92%8CJava%E6%B7%B7%E5%90%88%E6%8E%A7%E5%88%B6UI%E7%95%8C%E9%9D%A2"><span class="nav-text">(3).使用XML和Java混合控制UI界面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E5%BC%80%E5%8F%91%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84View"><span class="nav-text">(4).开发自定义的View</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-text">五、碎片(手机平板的兼容)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%9F%BA%E7%A1%80-2"><span class="nav-text">1.基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F"><span class="nav-text">2.使用方式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E7%AE%80%E5%8D%95%E7%94%A8%E6%B3%95"><span class="nav-text">(1).简单用法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E5%8A%A8%E6%80%81%E6%B7%BB%E5%8A%A0%E7%A2%8E%E7%89%87"><span class="nav-text">(2).动态添加碎片</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#a-%E6%96%B9%E6%B3%95"><span class="nav-text">a).方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#b-%E5%BC%95%E7%94%B3"><span class="nav-text">b).引申</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%9C%A8%E7%A2%8E%E7%89%87%E4%B8%AD%E8%BF%94%E5%9B%9E%E6%A0%88"><span class="nav-text">(3).在碎片中返回栈</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E7%A2%8E%E7%89%87%E5%92%8C%E6%B4%BB%E5%8A%A8%E7%9A%84%E9%80%9A%E4%BF%A1"><span class="nav-text">(4).碎片和活动的通信</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="nav-text">3.生命周期</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81"><span class="nav-text">(1).运行状态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E6%9A%82%E5%81%9C%E7%8A%B6%E6%80%81"><span class="nav-text">(2).暂停状态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%81%9C%E6%AD%A2%E7%8A%B6%E6%80%81"><span class="nav-text">(3).停止状态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E9%94%80%E6%AF%81%E7%8A%B6%E6%80%81"><span class="nav-text">(4).销毁状态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-%E9%99%84%E5%8A%A0%E5%9B%9E%E8%B0%83%E6%96%B9%E6%B3%95"><span class="nav-text">(5).附加回调方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-text">六、广播接收器</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%9F%BA%E7%A1%80-3"><span class="nav-text">1.基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%8E%A5%E6%94%B6%E7%B3%BB%E7%BB%9F%E5%B9%BF%E6%92%AD"><span class="nav-text">2.接收系统广播</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E5%8A%A8%E6%80%81%E6%B3%A8%E5%86%8C"><span class="nav-text">(1).动态注册</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-text">附、问题集合</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-Android-Studio%E5%90%AF%E5%8A%A8%E5%90%8Egradle%E4%B8%8B%E8%BD%BD%E5%A4%AA%E6%85%A2"><span class="nav-text">1.Android Studio启动后gradle下载太慢</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E7%BB%99-Button-%E6%B7%BB%E5%8A%A0%E8%83%8C%E6%99%AF%E4%B9%8B%E5%90%8E%E4%B8%8D%E6%98%BE%E7%A4%BA"><span class="nav-text">2.给 Button 添加背景之后不显示</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%A6%82%E4%BD%95%E4%BF%AE%E6%94%B9AS%E7%9A%84%E6%A8%A1%E6%8B%9F%E5%99%A8%E4%BD%8D%E7%BD%AE"><span class="nav-text">3.如何修改AS的模拟器位置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%A6%82%E4%BD%95%E4%BF%AE%E6%94%B9Android%E9%A1%B9%E7%9B%AE%E7%9A%84%E5%8C%85%E5%90%8D"><span class="nav-text">4.如何修改Android项目的包名</span></a></li></ol></li></ol></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" alt="Zhang Yangeng" src="/images/avatar.jpg"><p class="site-author-name" itemprop="name">Zhang Yangeng</p><div class="site-description" itemprop="description">保持独立思考,不卑不亢不怂,长成自己想要的样子!</div></div><div class="site-state-wrap site-overview-item animated"><nav class="site-state"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">69</span> <span class="site-state-item-name">日志</span></a></div><div class="site-state-item site-state-categories"><a href="/categories/"><span class="site-state-item-count">13</span> <span class="site-state-item-name">分类</span></a></div><div class="site-state-item site-state-tags"><a href="/tags/"><span class="site-state-item-count">52</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author site-overview-item animated"><span class="links-of-author-item"><a href="https://github.com/zhangyangeng" title="GitHub → https://github.com/zhangyangeng" rel="external nofollow noopener noreferrer" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a> </span><span class="links-of-author-item"><a href="https://weibo.com/u/2294901673" title="weibo → https://weibo.com/u/2294901673" rel="external nofollow noopener noreferrer" target="_blank"><i class="fab fa-weibo fa-fw"></i>weibo</a></span></div><div class="cc-license site-overview-item animated" itemprop="license"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-cn" class="cc-opacity" rel="external nofollow noopener noreferrer" target="_blank"><img src="https://cdn.jsdelivr.net/npm/@creativecommons/[email protected]/assets/license_badges/small/by_nc_sa.svg" alt="Creative Commons"></a></div><div class="links-of-blogroll site-overview-item animated"><div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i> 推荐网站</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="http://topbook.cc/" title="http://topbook.cc/" rel="external nofollow noopener noreferrer" target="_blank">Topbook</a></li></ul></div></div></div></div></aside><div class="sidebar-dimmer"></div></header><div class="back-to-top" role="button" aria-label="返回顶部"><i class="fa fa-arrow-up"></i> <span>0%</span></div><div class="reading-progress-bar"></div><a role="button" class="book-mark-link book-mark-link-fixed"></a><noscript><div class="noscript-warning">Theme NexT works best with JavaScript enabled</div></noscript><div class="main-inner post posts-expand"><div class="post-block"><article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN"><link itemprop="mainEntityOfPage" href="https://www.wrysmile.cn/Angular-Basics.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/images/avatar.jpg"><meta itemprop="name" content="Zhang Yangeng"><meta itemprop="description" content="保持独立思考,不卑不亢不怂,长成自己想要的样子!"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Wrysmile 的博客"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">学习笔记:Android</h1><div class="post-meta-container"><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间:2020-08-31 08:26:24" itemprop="dateCreated datePublished" datetime="2020-08-31T08:26:24+08:00">2020-08-31</time> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="far fa-calendar-check"></i> </span><span class="post-meta-item-text">更新于</span> <time title="修改时间:2023-01-31 18:23:56" itemprop="dateModified" datetime="2023-01-31T18:23:56+08:00">2023-01-31</time> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="far fa-folder"></i> </span><span class="post-meta-item-text">分类于</span> <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">学习笔记</span></a> </span></span><span id="/Angular-Basics.html" class="post-meta-item leancloud_visitors" data-flag-title="学习笔记:Android" title="阅读次数"><span class="post-meta-item-icon"><i class="far fa-eye"></i> </span><span class="post-meta-item-text">阅读次数:</span> <span class="leancloud-visitors-count"></span></span></div><div class="post-meta"><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">本文字数:</span> <span>14k</span> </span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="far fa-clock"></i> </span><span class="post-meta-item-text">阅读时长 ≈</span> <span>13 分钟</span></span></div></div></header><div class="post-body" itemprop="articleBody"><center>本篇是 Android 开发中需要掌握的基础内容</center><span id="more"></span><h1>一、前言</h1><h2 id="1-开发方向">1.开发方向</h2><h3 id="1-传统Windows开发">(1).传统Windows开发</h3><ul class="lvl-0"><li class="lvl-2"><p>SDK、DDK、C++、C#(.Net Framework、.Net Core)</p></li></ul><h3 id="2-移动开发">(2).移动开发</h3><ul class="lvl-0"><li class="lvl-2"><p>HTML+CSS、AJAX、JS、XML(XPath)、图形图像</p></li><li class="lvl-2"><p>基于 ARM 架构</p></li><li class="lvl-2"><p>SOC</p></li></ul><h3 id="3-Web开发">(3).Web开发</h3><ul class="lvl-0"><li class="lvl-2"><p>CoM</p></li><li class="lvl-2"><p>前端:HTML+CSS、AJAX、JS、图形图像</p></li><li class="lvl-2"><p>后台:CGI+DB,PHP,<a target="_blank" rel="external nofollow noopener noreferrer" href="http://ASP.NET">ASP.NET</a>、JSP</p></li></ul><h3 id="4-嵌入式开发">(4).嵌入式开发</h3><h2 id="2-学习内容">2.学习内容</h2><ul class="lvl-0"><li class="lvl-2"><p>算法(数据结构)</p></li><li class="lvl-2"><p>接口</p></li><li class="lvl-2"><p>方法论</p></li></ul><h1>二、基础内容</h1><h2 id="1-零碎">1.零碎</h2><ul class="lvl-0"><li class="lvl-2"><p>Android 讲究逻辑设视图分离 —— 在布局文件中编写界面,然后在活动中引入进来</p></li><li class="lvl-2"><p>在 <code>res</code> 文件夹下最后自己再创建 <code>drawable-hdpi、drawable-xhdpi、drawable-xxhdpi</code> 等文件夹,用来存放不同分辨率的图片</p></li></ul><h2 id="2-环境搭建">2.环境搭建</h2><ul class="lvl-0"><li class="lvl-2"><p>关于软件下载,可以去<a target="_blank" rel="external nofollow noopener noreferrer" href="https://www.androiddevtools.cn/">这个</a>网站</p></li><li class="lvl-2"><p>关于安卓信息,可以去<a target="_blank" rel="external nofollow noopener noreferrer" href="https://developer.android.google.cn/">这个</a>网站了解</p></li></ul><h3 id="1-ADT">(1).ADT</h3><ul class="lvl-0"><li class="lvl-2"><p>关于ADT版本和SDK Tools的对应版本可以查看<a target="_blank" rel="external nofollow noopener noreferrer" href="https://developer.android.com/studio/intro">这里</a>,里面详细说明了不同版本的ADT所对应的JDK版本要求,eclipse版本要求及SDK Tools版本要求。</p></li></ul><h3 id="2-Android-Studio">(2).Android Studio</h3><ul class="lvl-0"><li class="lvl-2"><p>关于其概述,可以查看<a target="_blank" rel="external nofollow noopener noreferrer" href="https://developer.android.com/studio/intro">这里</a></p></li><li class="lvl-2"><p>安装教程查看<a target="_blank" rel="external nofollow noopener noreferrer" href="https://zhuanlan.zhihu.com/p/80051318">这里</a></p></li></ul><h2 id="3-日志工具">3.日志工具</h2><ul class="lvl-0"><li class="lvl-2"><p>Android 中的日志工具类是 Log,该类中提供了以下五个方法:<br>Log.v():对应级别verbose,打印所有日志信息<br>Log.d():对应级别debug,打印调试信息<br>Log.i():对应级别info,打印比较重要的数据<br>Log.w():对应级别warn,打印警告信息<br>Log.e():对应级别error,打印错误信息</p></li><li class="lvl-2"><p>该方法中需要两个字符串参数:<br>tag:用于对打印信息进行过滤<br>msg:想要打印的具体内容</p></li></ul><h1>三、活动(Activity)</h1><h2 id="1-基础">1.基础</h2><ul class="lvl-0"><li class="lvl-2"><p>项目中的任何活动都应该重写 Activity 的 onCreate() 方法</p></li></ul><h2 id="2-简单编写">2.简单编写</h2><h3 id="1-创建活动">(1).创建活动</h3><ul class="lvl-0"><li class="lvl-2"><p>在项目的 <code>app/src/main/java</code> 下的包中右键新建 Empty Activity</p></li></ul><h3 id="2-创建布局文件">(2).创建布局文件</h3><ul class="lvl-0"><li class="lvl-2"><p>在项目的 <code>app/src/main/res</code> 下右键新建一个Directory,并将其命名为</p></li></ul><h3 id="3-设计布局文件">(3).设计布局文件</h3><h3 id="4-加载布局文件">(4).加载布局文件</h3><ul class="lvl-0"><li class="lvl-2"><p>使用 setContentView() 方法,一般需要传入一个布局文件的id</p></li></ul><h3 id="5-注册活动">(5).注册活动</h3><ul class="lvl-0"><li class="lvl-2"><p>将活动在 AndroidManifest.xml 文件中注册</p></li><li class="lvl-2"><p>活动的注册声明要放在 <code><application></code> 标签内,通过 <code><activity></code> 标签来对活动进行注册</p></li><li class="lvl-2"><p>在 <code><activity></code> 标签中使用 <code>android:name</code> 来指定具体注册哪一个活动,因为前面包名已经指定,所以只需要写 <code>.活动名</code> 即可</p></li></ul><h3 id="6-配置主活动">(6).配置主活动</h3><ul class="lvl-0"><li class="lvl-2"><p>在 <code><activity></code> 标签内部加入 <code><intent-filter></code> 标签,并在标签中写入如下内容:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"> <activity android:name=".FirstActivity"</span><br><span class="line"> android:label="FirstActivity"> <!--指定活动中标题栏内容,并且成为应用名--></span><br><span class="line"> <intent-filter></span><br><span class="line"> <action android:name="android.intent.action.MAIN" /></span><br><span class="line"> <category android:name="android.intent.category.LAUNCHER" /></span><br><span class="line"> </intent-filter></span><br><span class="line"></activity></span><br></pre></td></tr></table></figure><h3 id="7-销毁活动">(7).销毁活动</h3><ul class="lvl-0"><li class="lvl-2"><p>第一种:按下Back键就可以销毁当前的活动</p></li><li class="lvl-2"><p>第二种:调用Activity类中的finish() 方法</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@Override</span><br><span class="line">public void onClick(View v){</span><br><span class="line"> finish();</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="3-Toast">3.Toast</h2><ul class="lvl-0"><li class="lvl-2"><p>通过静态方法 <code>makeText()</code> 创建出一个 Toast 对象,然后调用 <code>show()</code> 将 Toast 显示出来就可以了</p></li><li class="lvl-2"><p>该方法需要传入3个参数:<br>Context:Toast要求的上下文<br>Text:Toast显示的文本内容<br>Time:Toast显示的时长,可选值为:Toast.LENGTH_SHORT与Toast.LENGTH_LONG</p></li><li class="lvl-2"><p>如下就是通过点击一个按钮来使其显示 Toast</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">protected void onCreate(Bundle savedInstanceState) {</span><br><span class="line"> super.onCreate(savedInstanceState);</span><br><span class="line"> setContentView(R.layout.first_layout);</span><br><span class="line"> // 获取到在布局文件中定义的元素并返回View对象</span><br><span class="line"> Button button1 = (Button) findViewById(R.id.button_1);</span><br><span class="line"> // 为按钮注册一个监听器</span><br><span class="line"> button1.setOnClickListener(new View.OnClickListener(){</span><br><span class="line"> // 为按钮添加单击响应事件</span><br><span class="line"> @Override</span><br><span class="line"> public void onClick(View v){</span><br><span class="line"> Toast.makeText(FirstActivity.this,"You clicked Button 1",Toast.LENGTH_SHORT).show();</span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Menu">4.Menu</h2><ul class="lvl-0"><li class="lvl-2"></li></ul><h2 id="5-Intent">5.Intent</h2><ul class="lvl-0"><li class="lvl-2"></li></ul><h2 id="6-生命周期">6.生命周期</h2><ul class="lvl-0"><li class="lvl-2"></li></ul><h2 id="7-启动模式">7.启动模式</h2><h3 id="1-standard">(1).standard</h3><ul class="lvl-0"><li class="lvl-2"></li></ul><h3 id="2-singleTop">(2).singleTop</h3><ul class="lvl-0"><li class="lvl-2"></li></ul><h3 id="3-singleTask">(3).singleTask</h3><ul class="lvl-0"><li class="lvl-2"></li></ul><h3 id="4-singleInstance">(4).singleInstance</h3><ul class="lvl-0"><li class="lvl-2"></li></ul><h2 id="8-活动的最佳实践">8.活动的最佳实践</h2><h3 id="1-知晓当前在哪一个活动">(1).知晓当前在哪一个活动</h3><ul class="lvl-0"><li class="lvl-2"></li></ul><h3 id="2-随时随地退出程序">(2).随时随地退出程序</h3><ul class="lvl-0"><li class="lvl-2"></li></ul><h3 id="3-启动活动的最佳写法">(3).启动活动的最佳写法</h3><ul class="lvl-0"><li class="lvl-2"></li></ul><h1>四、UI 设计</h1><h2 id="1-视图(View)">1.视图(View)</h2><ul class="lvl-0"><li class="lvl-2"><p>任何可视化控件都需要从 <code>android.view.View</code> 类中继承,而任何继承自该类的类都称为视图</p></li><li class="lvl-2"><p>View 可以分为三种:布局(layout)、视图容器类(View Container)、视图类(Button、TextView、EditText等)</p></li><li class="lvl-2"><p>视图的继承关系如下图:<br><img src="https://s3.ax1x.com/2020/11/16/DAw0aT.png" alt="Android02.png"></p></li></ul><h2 id="2-视图之视图类">2.视图之视图类</h2><h3 id="1-TextView">(1).TextView</h3><ul class="lvl-0"><li class="lvl-2"><p>主要用于在界面上显示一段文本信息</p></li></ul><h3 id="2-Button">(2).Button</h3><ul class="lvl-0"><li class="lvl-2"><p>主要用于在界面上显示一个按钮</p></li><li class="lvl-2"><p>在布局文件中设置的文字有小写,但实际会转为大写,可以添加如下文件来禁用这一默认特性:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><Button</span><br><span class="line"> android:id="@+id/button"</span><br><span class="line"> android:layout_width="match_parent"</span><br><span class="line"> android:layout_height="wrap_content"</span><br><span class="line"> android:textAllCaps="false" //禁用默认特性</span><br><span class="line"> android:text="Button" /></span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>绑定点击事件之匿名类注册监听器,如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">public class MainActivity extends AppCompatActivity {</span><br><span class="line"> @Override</span><br><span class="line"> protected void onCreate(Bundle savedInstanceState) {</span><br><span class="line"> super.onCreate(savedInstanceState);</span><br><span class="line"> setContentView(R.layout.activity_main);</span><br><span class="line"> Button button = (Button) findViewById(R.id.button);</span><br><span class="line"> button.setOnClickListener(new View.OnClickListener(){</span><br><span class="line"> @Override</span><br><span class="line"> public void onClick(View v){</span><br><span class="line"> //此处写逻辑</span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>绑定点击事件之实现接口注册监听器,如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">public class MainActivity extends AppCompatActivity implements View.OnClickListener{</span><br><span class="line"> @Override</span><br><span class="line"> protected void onCreate(Bundle savedInstanceState) {</span><br><span class="line"> super.onCreate(savedInstanceState);</span><br><span class="line"> setContentView(R.layout.activity_main);</span><br><span class="line"> Button button = (Button) findViewById(R.id.button);</span><br><span class="line"> // 实现接口方式注册监听器</span><br><span class="line"> button.setOnClickListener(this);</span><br><span class="line"> }</span><br><span class="line"> @Override</span><br><span class="line"> public void onClick(View v){</span><br><span class="line"> switch(v.getId()){</span><br><span class="line"> case R.id.button:</span><br><span class="line"> //此处写逻辑</span><br><span class="line"> break;</span><br><span class="line"> default:</span><br><span class="line"> break;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="3-EditText">(3).EditText</h3><ul class="lvl-0"><li class="lvl-2"><p>主要用于在控件里输入和编辑内容,并可以在程序中对这些内容进行处理</p></li></ul><h3 id="4-ImageView">(4).ImageView</h3><ul class="lvl-0"><li class="lvl-2"><p>主要用于引入图片并进行相关操作</p></li><li class="lvl-2"><p>在引入之前最后自己在 res 目录下自己新建一个 <code>drawable-xhdpi</code> 的文件夹并将图片放入其中</p></li></ul><h3 id="5-ProgressBar">(5).ProgressBar</h3><ul class="lvl-0"><li class="lvl-2"><p>主要用于在界面上显示一个进度条,表示程序正在加载一些数据</p></li><li class="lvl-2"><p>如果想要更改进度条的样式,可以如下设置:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><ProgressBar</span><br><span class="line"> android:id="@+id/progress_bar"</span><br><span class="line"> android:layout_width="match_parent"</span><br><span class="line"> android:layout_height="wrap_content"</span><br><span class="line"> // 更改进度条样式并设置最大值</span><br><span class="line"> style="?android:attr/progressBarStyleHorizontal"</span><br><span class="line"> android:max="100" /></span><br></pre></td></tr></table></figure><h3 id="6-AlertDialog">(6).AlertDialog</h3><ul class="lvl-0"><li class="lvl-2"><p>可以在当前界面弹出一个对话框,且置顶于所有界面元素之上的</p></li><li class="lvl-2"><p>具体实现如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">// 点击按钮弹出一个对话框</span><br><span class="line">@Override</span><br><span class="line">public void onClick(View v){</span><br><span class="line"> switch (v.getId()){</span><br><span class="line"> case R.id.button:</span><br><span class="line"> AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);</span><br><span class="line"> dialog.setTitle("This is Dialog");</span><br><span class="line"> dialog.setMessage("这很重要,你确定要删除吗?");</span><br><span class="line"> // 设置可以用返回键来关闭对话框</span><br><span class="line"> dialog.setCancelable(false);</span><br><span class="line"> dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {</span><br><span class="line"> @Override</span><br><span class="line"> public void onClick(DialogInterface dialog, int which) {</span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line"> dialog.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {</span><br><span class="line"> @Override</span><br><span class="line"> public void onClick(DialogInterface dialog, int which) {</span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line"> // 显示对话框</span><br><span class="line"> dialog.show();</span><br><span class="line"> break;</span><br><span class="line"> default:</span><br><span class="line"> break;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="7-ProgressDialog">(7).ProgressDialog</h3><ul class="lvl-0"><li class="lvl-2"><p>可以在当前界面弹出一个对话框,且置顶于所有界面元素之上的,区别于上面的是,该对话框可以显示进度条,一般用于表示当前操作比较耗时</p></li><li class="lvl-2"><p>具体实现如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">// 点击按钮弹出对话框且显示进度条</span><br><span class="line">@Override</span><br><span class="line">public void onClick(View v){</span><br><span class="line"> switch (v.getId()){</span><br><span class="line"> case R.id.button:</span><br><span class="line"> ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);</span><br><span class="line"> progressDialog.setTitle("This is ProgressDialog");</span><br><span class="line"> progressDialog.setMessage("Loading....");</span><br><span class="line"> progressDialog.setCancelable(true);</span><br><span class="line"> progressDialog.show();</span><br><span class="line"> break;</span><br><span class="line"> default:</span><br><span class="line"> break;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="8-相关属性">(8).相关属性</h3><h4 id="a-android-id-属性">a).android:id 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>语法如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">android:id="@+id/user"</span><br></pre></td></tr></table></figure><h4 id="b-android-background-属性">b).android:background 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>语法如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">android:background="@mipmap/bg"</span><br><span class="line">android:background="#bfa"</span><br></pre></td></tr></table></figure><h4 id="c-android-padding-属性">c).android:padding 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>语法如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">android:padding="@dimen/activity_margin"</span><br><span class="line">android:padding="16dp"</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>还包括如下四个:<br>android:paddingLeft<br>android:paddingTop<br>android:paddingRight<br>android:paddingBottom</p></li><li class="lvl-2"><p>API 17新增加:<br>android:paddingStart<br>android:paddingEnd</p></li></ul><h4 id="d-android-gravity-属性">d).android:gravity 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>用于指定文字的对齐方式,可选值有:top/bottom/left/right/center,也可以用 <code>|</code> 来指定多个值</p></li></ul><h4 id="e-android-textSize-属性">e).android:textSize 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>用于设置文字的大小,在Android中字体大小时使用 sp 作为单位的</p></li></ul><h4 id="f-android-hint-属性">f).android:hint 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>常在EditText中使用,可以指定一段提示性文字</p></li></ul><h4 id="g-android-maxLines-属性">g).android:maxLines 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>常在EditText中使用,可以设置最大行数</p></li></ul><h4 id="h-android-visibility-属性">h).android:visibility 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>所有控件都可以使用,用于设置控件的可见属性</p></li><li class="lvl-2"><p>可选值如下:<br>visible:可见的,默认值<br>invisible:不可见的,但仍占据空间<br>gone:不可见的,且不占据任何空间</p></li><li class="lvl-2"><p>也可以使用代码设置控件的可见性,使用 <code>setVisibility()</code> 方法,可以传入 <code>View.VISIBLE View.INVISIBLE View.GONE</code> 三个值</p></li></ul><h2 id="3-视图之布局">3.视图之布局</h2><ul class="lvl-0"><li class="lvl-2"><p>布局是一种可用于放置很多控件的容器,可以按照一定规律调整内部控件的位置</p></li></ul><h3 id="1-线性布局(LinearLayout)">(1).线性布局(LinearLayout)</h3><ul class="lvl-0"><li class="lvl-2"><p>在线性布局中,vertical下,高度就不可以指定为match;horizontal下,宽度就不可以指定为match</p></li><li class="lvl-2"><p>相关属性请看下面的 <code>ab</code></p></li></ul><h3 id="2-相对布局(RelativeLayout)">(2).相对布局(RelativeLayout)</h3><ul class="lvl-0"><li class="lvl-2"><p>可以通过相对定位的方式让控件出现在布局的任何位置</p></li><li class="lvl-2"><p>相关属性请看下面的 <code>c~g</code></p></li></ul><h3 id="3-帧布局(FrameLayout)">(3).帧布局(FrameLayout)</h3><ul class="lvl-0"><li class="lvl-2"><p>所有的控件都会默认摆放在布局的左上角</p></li><li class="lvl-2"><p>相关属性请看下面的 <code>a</code></p></li></ul><h3 id="4-百分比布局">(4).百分比布局</h3><ul class="lvl-0"><li class="lvl-2"><p>该布局只是作为相对布局和帧布局的拓展,分别为:PercentFrameLayout 和 PercentRelativeLayout</p></li><li class="lvl-2"><p>只需要在项目的 build.gradle 中添加百分比布局库的依赖即可在所有系统版本上的兼容性了,打开 app/build.gradle ,在 dependencies 闭包中添加如下内容的最后一行,然后点击 <code>Sync Now</code> 即可:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">dependencies {</span><br><span class="line"> implementation 'androidx.appcompat:appcompat:1.2.0'</span><br><span class="line"> implementation 'com.google.android.material:material:1.2.1'</span><br><span class="line"> implementation 'androidx.constraintlayout:constraintlayout:2.0.4'</span><br><span class="line"> testImplementation 'junit:junit:4.+'</span><br><span class="line"> androidTestImplementation 'androidx.test.ext:junit:1.1.2'</span><br><span class="line"> androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'</span><br><span class="line"> implementation 'com.android.support:percent:24.2.1'</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="5-相关属性">(5).相关属性</h3><h4 id="a-android-layout-gravity-属性">a).android:layout_gravity 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>用于指定控件在布局中的对齐方式</p></li></ul><h4 id="b-android-layout-weight-属性">b).android:layout_weight 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>用于使用比例的方式来指定控件的大小</p></li><li class="lvl-2"><p>使用该属性时,可以将宽度修改为 <code>0dp</code> ,然后将该属性设置为1,则可以实现控件自动平分宽度</p></li><li class="lvl-2"><p>在同一方向上也可以指定部分控件的该属性,使其自动适配</p></li></ul><h4 id="c-android-layout-alignParentXxx-属性">c).android:layout_alignParentXxx 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>其中XXX包含Left、Right、Top、Bottom</p></li><li class="lvl-2"><p>使其相对于父元素定位</p></li></ul><h4 id="d-android-layout-centerInParent-属性">d).android:layout_centerInParent 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>使其相对于父元素居中</p></li></ul><h4 id="e-android-layout-above-below-属性">e).android:layout_above/below 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>可以让一个控件位于另一个控件的上方/下方</p></li><li class="lvl-2"><p>使用该属性时作为参照物的控件需要写在最上边</p></li></ul><h4 id="f-android-layout-toLeftOf-toRightOf-属性">f).android:layout_toLeftOf/toRightOf 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>可以让一个控件位于另一个控件的左侧/右侧</p></li><li class="lvl-2"><p>使用该属性时作为参照物的控件需要写在最上边</p></li></ul><h4 id="g-android-layout-alignXXX-属性">g).android:layout_alignXXX 属性</h4><ul class="lvl-0"><li class="lvl-2"><p>其中XXX包含Left、Right、Top、Bottom</p></li><li class="lvl-2"><p>可以让一个控件的左/右/上/下边缘与另一个控件的边缘对齐</p></li></ul><h3 id="6-引入布局或自定义控件">(6).引入布局或自定义控件</h3><ul class="lvl-0"><li class="lvl-2"><p>通过引用布局,可以减少重复代码的编写</p></li><li class="lvl-2"><p>当引入的布局中有些需要绑定点击事件时,就需要自定义控件来解决该问题了</p></li></ul><h4 id="a-引入布局">a).引入布局</h4><ul class="lvl-0"><li class="lvl-2"><p>新建一个布局文件并编写好,在 <code>activity_main.xml</code> 中使用以下语法来引入:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><include layout="@layout/title" /></span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>如果需要去除系统自带的标题栏,则需要在 <code>MainActivity.java</code> 文件中这样编写:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ActionBar actionbar = getSupportActionBar();</span><br><span class="line">if(actionbar != null){</span><br><span class="line"> actionbar.hide();</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="b-自定义控件">b).自定义控件</h4><ul class="lvl-0"><li class="lvl-2"><p>新建一个java文件来继承自 <code>LinearLayout</code> ,并重写其构造函数,如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">public class TitleLayout extends LinearLayout {</span><br><span class="line"> public TitleLayout(Context context, AttributeSet attrs){</span><br><span class="line"> super(context,attrs);</span><br><span class="line"> LayoutInflater.from(context).inflate(R.layout.title,this);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>在布局文件中添加该自定义控件,如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"</span><br><span class="line"> android:layout_width="match_parent"</span><br><span class="line"> android:layout_height="match_parent"></span><br><span class="line"> <!-- 引入自定义控件 --></span><br><span class="line"> <com.wrysmile.uilayouttest.TitleLayout</span><br><span class="line"> android:layout_width="match_parent"</span><br><span class="line"> android:layout_height="wrap_content" /></span><br><span class="line"></LinearLayout></span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>在自定义控件中编写适当的点击事件即可</p></li></ul><h2 id="4-视图之视图容器类">4.视图之视图容器类</h2><h3 id="1-ListView">(1).ListView</h3><ul class="lvl-0"><li class="lvl-2"><p>当程序有大量数据时,使用该空间可以将屏幕外的数据滚入,屏幕内的数据滚出</p></li></ul><h4 id="b-点击事件">b).点击事件</h4><ul class="lvl-0"><li class="lvl-2"><p>我们需要使用 <code>setOnItemClickListener()</code> 方法为ListView注册一个监听器,当执行点击事件时,就会回调 <code>onItemClick()</code> 方法</p></li><li class="lvl-2"><p>在该方法中通过 position 来判断点击的是哪一个子项,然后执行相应的操作,可看下方:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">private List<Fruit> fruitList = new ArrayList<>();</span><br><span class="line"> @Override</span><br><span class="line"> protected void onCreate(Bundle savedInstanceState) {</span><br><span class="line"> super.onCreate(savedInstanceState);</span><br><span class="line"> setContentView(R.layout.activity_main);</span><br><span class="line"> // 初始化水果数据</span><br><span class="line"> initFruits();</span><br><span class="line"> FruitAdapter adapter = new FruitAdapter(MainActivity.this,R.layout.fruit_item,fruitList);</span><br><span class="line"> ListView listView = (ListView) findViewById(R.id.list_view);</span><br><span class="line"> listView.setAdapter(adapter);</span><br><span class="line"> // 点击事件</span><br><span class="line"> listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {</span><br><span class="line"> @Override</span><br><span class="line"> public void onItemClick(AdapterView<?> parent, View view, int position, long id){</span><br><span class="line"> Fruit fruit = fruitList.get(position);</span><br><span class="line"> Toast.makeText(MainActivity.this,fruit.getName(),Toast.LENGTH_SHORT).show();</span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="2-RecyclerView">(2).RecyclerView</h3><ul class="lvl-0"><li class="lvl-2"><p>增强版的 ListView,具有同样的效果,还优化了性能问题</p></li><li class="lvl-2"><p>和百分比布局类似,它也属于新增的控件,需要在项目的 build.gradle 中的 dependencies 闭包中添加如下内容:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">implementation 'androidx.recyclerview:recyclerview:1.1.0'</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>然后在 activity_main.xml 文件中这样编写即可</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><?xml version="1.0" encoding="utf-8"?></span><br><span class="line"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"</span><br><span class="line"> android:layout_width="match_parent"</span><br><span class="line"> android:layout_height="match_parent"></span><br><span class="line"> <androidx.recyclerview.widget.RecyclerView</span><br><span class="line"> android:id="@+id/recycler_view"</span><br><span class="line"> android:layout_width="match_parent"</span><br><span class="line"> android:layout_height="match_parent" /></span><br><span class="line"></LinearLayout></span><br></pre></td></tr></table></figure><h4 id="a-点击事件">a).点击事件</h4><h2 id="5-制作-Nine-Patch-图片">5.制作 Nine-Patch 图片</h2><ul class="lvl-0"><li class="lvl-2"><p>Nine-Patch 图片可以让某一图片动态的跟随内容变换其长度和高度,而不是单纯的让图片平铺在背景上,主要用于实现类似于聊天框的效果</p></li><li class="lvl-2"><p>将图片导入到项目中的 <code>drawable-xhdpi</code> 文件夹中,右击该图片,找到 <code>Create 9-patch file</code> 按钮,点击就进入了制作界面</p></li><li class="lvl-2"><p>类似于 PS 的画笔功能,可以在四边用鼠标进行绘画一条直线,上边和左边是控制哪部分拉伸的,下边和右边是控制文本在哪里显示的</p></li><li class="lvl-2"><p>修改好后右边可以看到效果图,满意保存替换源文件即可</p></li></ul><h2 id="2-ViewGroup-类">2.ViewGroup 类</h2><ul class="lvl-0"><li class="lvl-2"><p>它是一个抽象类,一般使用其子类来实现</p></li><li class="lvl-2"><p>该类控制其子组件分布时依赖如下两个内部类:</p></li></ul><h3 id="1-ViewGroup-LayoutParams-类">(1).ViewGroup.LayoutParams 类</h3><ul class="lvl-0"><li class="lvl-2"><p>该类主要控制布局的位置、高度和宽度的</p></li><li class="lvl-2"><p>通常使用以下两个属性:<br>android:layout_height:设置布局高度<br>android:layout_width:设置布局宽度</p></li><li class="lvl-2"><p>这两个属性有如下属性值:<br>fill_parent:与父容器形同(API8以下使用)<br>match_parent:与父容器相同<br>wrap_content:包裹其自身的内容</p></li></ul><h3 id="2-ViewGroup-MarginLayoutParams-类">(2).ViewGroup.MarginLayoutParams 类</h3><ul class="lvl-0"><li class="lvl-2"><p>主要用于控制子组件的外边距</p></li><li class="lvl-2"><p>通常包括四个属性:<br>android:layout_marginLeft<br>android:layout_marginTop<br>android:layout_marginRight<br>android:layout_marginBottom</p></li><li class="lvl-2"><p>API 17新增加:<br>android:paddingStart<br>android:paddingEnd</p></li></ul><h2 id="3-UI组件的层次结构">3.UI组件的层次结构</h2><ul class="lvl-0"><li class="lvl-2"><p>如下图:<br><img src="https://s1.ax1x.com/2020/10/20/0zbYFJ.png" alt="Android01.png"></p></li></ul><h2 id="4-控制UI界面的方法">4.控制UI界面的方法</h2><h3 id="1-使用XML布局文件控制UI界面">(1).使用XML布局文件控制UI界面</h3><ul class="lvl-0"><li class="lvl-2"><p>在 <code>res/layout</code> 目录下编写XML布局文件</p></li><li class="lvl-2"><p>在 Activity 中使用以下Java代码来显示XML文件中布局的内容</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">setContentView(R.layout.activity_main);</span><br></pre></td></tr></table></figure><h3 id="2-在Java代码中控制UI界面">(2).在Java代码中控制UI界面</h3><ul class="lvl-0"><li class="lvl-2"><p>新建的 MainActivity 类应该继承自 AppCompatActivity 类</p></li><li class="lvl-2"><p>然后重写 onCreate 方法,且所有代码都得写在 <code>super.onCreate(savedInstanceState);</code> 语句的后面</p></li><li class="lvl-2"><p>中间代码设置背景等样式</p></li><li class="lvl-2"><p>还可以为按钮绑定单击响应事件</p></li><li class="lvl-2"><p>最后需要将写好的内容通过以下代码加入 View 中——<code>frameLayout.addView(text1);</code></p></li></ul><h3 id="3-使用XML和Java混合控制UI界面">(3).使用XML和Java混合控制UI界面</h3><h3 id="4-开发自定义的View">(4).开发自定义的View</h3><h1>五、碎片(手机平板的兼容)</h1><h2 id="1-基础-2">1.基础</h2><ul class="lvl-0"><li class="lvl-2"><p>碎片是一种可以嵌入在活动当中的 UI 片段,一般用于平板视图中</p></li></ul><h2 id="2-使用方式">2.使用方式</h2><h3 id="1-简单用法">(1).简单用法</h3><ul class="lvl-0"><li class="lvl-2"><p>写一左一右两个布局文件</p></li><li class="lvl-2"><p>新建一左一右两个类并让其继承自 <code>Fragment</code> 类,并在这两个类中通过 LayoutInflater 的 inflate() 方法将刚才定义的布局加载进来</p></li><li class="lvl-2"><p>在 activity_main.xml 中使用 <code><fragment></code> 标签添加碎片</p></li><li class="lvl-2"><p><font color="#F00">注意:这里需要通过 android:name 属性来显示指明要添加的碎片类名</font></p></li></ul><h3 id="2-动态添加碎片">(2).动态添加碎片</h3><h4 id="a-方法">a).方法</h4><ul class="lvl-0"><li class="lvl-2"><p>创建待添加的碎片实例</p></li><li class="lvl-2"><p>获取 FragmentManager,在活动中可以直接调用 getSupportFragmentManager() 方法得到</p></li><li class="lvl-2"><p>开启一个事务,通过调用 beginTransaction() 方法开启</p></li><li class="lvl-2"><p>向容器内添加或替换碎片,一般使用 replace() 方法实现,需要传入容器的id和待添加的碎片实例</p></li><li class="lvl-2"><p>提交事务,调用 commit() 方法来完成</p></li></ul><h4 id="b-引申">b).引申</h4><ul class="lvl-0"><li class="lvl-2"><p>这里在 activity_main.xml 中加载布局可以使用 <code><FrameLayout></FrameLayout></code> 布局来写</p></li></ul><h3 id="3-在碎片中返回栈">(3).在碎片中返回栈</h3><ul class="lvl-0"><li class="lvl-2"><p>作用:使碎片像活动一样有返回栈,按 Back键时会回到上一个页面</p></li><li class="lvl-2"><p>FragmentTransaction 中提供了一个 addToBackStack() 方法,可以用于将一个事务添加到返回栈中,一般传 null 即可,如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">transaction.addToBackStack(null);</span><br></pre></td></tr></table></figure><h3 id="4-碎片和活动的通信">(4).碎片和活动的通信</h3><ul class="lvl-0"><li class="lvl-2"><p>从布局文件中获取碎片的实例:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">RightFragment rightFragment = (RightFragment) getSupportFragmentManager().findFragmentById(R.id.right_fragment);</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>从碎片中调用活动的方法:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">MainActivity activity = (MainActivity) getActivity();</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>引申:<font color="#F00">碎片与碎片之间的通信</font>可以先在一个碎片总得到与它相关联的活动,然后再通过这个活动去获取另外一个碎片的实例</p></li><li class="lvl-2"><p>引申:当碎片需要使用 Context 对象时,也可以使用 getActivity() 方法</p></li></ul><h2 id="3-生命周期">3.生命周期</h2><ul class="lvl-0"><li class="lvl-2"><p>生命周期示意图如下:</p></li></ul><h3 id="1-运行状态">(1).运行状态</h3><ul class="lvl-0"><li class="lvl-2"><p>碎片可见,且与之关联的活动正处于运行状态</p></li></ul><h3 id="2-暂停状态">(2).暂停状态</h3><ul class="lvl-0"><li class="lvl-2"><p>某一活动进入暂停状态,与之相关联的碎片也会处于暂停状态</p></li></ul><h3 id="3-停止状态">(3).停止状态</h3><ul class="lvl-0"><li class="lvl-2"><p>某一活动进入停止状态,与之相关联的碎片也会处于停止状态</p></li><li class="lvl-2"><p>通过调用 FragmentTransaction 的 remove()和replace() 方法将碎片从活动中移除,但在事务提交前调用 addToBackStack() 方法,也会处于停止状态</p></li></ul><h3 id="4-销毁状态">(4).销毁状态</h3><ul class="lvl-0"><li class="lvl-2"><p>某一活动被销毁时,与之相关联的碎片就会进入销毁状态</p></li><li class="lvl-2"><p>通过调用 FragmentTransaction 的 remove()和replace() 方法将碎片从活动中移除,但在事务提交前没有调用 addToBackStack() 方法,也会处于销毁状态</p></li></ul><h3 id="5-附加回调方法">(5).附加回调方法</h3><ul class="lvl-0"><li class="lvl-2"><p>onAttach():碎片和活动建立关联时调用</p></li><li class="lvl-2"><p>onCreateView():为碎片创建视图(加载布局)时调用</p></li><li class="lvl-2"><p>onActivityCreated():确保与碎片相关联的活动一定已经创建完毕时调用</p></li><li class="lvl-2"><p>onDestroyView():当与碎片相关联的视图被移除时调用</p></li><li class="lvl-2"><p>onDetach():当碎片和活动解除关联时调用</p></li></ul><h1>六、广播接收器</h1><h2 id="1-基础-3">1.基础</h2><ul class="lvl-0"><li class="lvl-2"><p>发送广播使用 Intent,而接收广播使用 Broadcast Receiver(广播接收器)</p></li><li class="lvl-2"><p>广播类型分为:标准广播:一种完全异步执行的广播,广播发出以后,所有的广播接收器几乎在同一时刻接收到这条广播信息有序广播:一种同步执行的广播,广播发出以后,同一时刻只有一个广播接收器能收到这条广播信息,当这个广播接收器中的逻辑执行完毕后,广播才会继续传递</p></li></ul><h2 id="2-接收系统广播">2.接收系统广播</h2><h3 id="1-动态注册">(1).动态注册</h3><ul class="lvl-0"><li class="lvl-2"><p>广播接收器想要监听什么广播,就使用 intentFilter 添加相应的 action 即可</p></li><li class="lvl-2"><p>动态注册的广播接收器一定要取消注册才行,可以在 onDestroy() 方法中调用 unregisterReceiver() 方法来实现</p></li><li class="lvl-2"><p><font color="#F00">注意 Android 系统为了保护用户设备的安全和隐私,做了严格的规定</font>:如果程序需要进行一些对用户来说比较敏感的操作,就必须在配置文件中声明权限才可以,否则程序会直接崩溃</p></li></ul><h1>附、问题集合</h1><h2 id="1-Android-Studio启动后gradle下载太慢">1.Android Studio启动后gradle下载太慢</h2><ul class="lvl-0"><li class="lvl-2"><p>在尝试进行第一次编译程序时,发现gradle下载很慢,即使挂梯子也下载很慢,于是在网上找到需要的压缩包进行自行配置,需要的可以点击<a target="_blank" rel="external nofollow noopener noreferrer" href="https://pan.baidu.com/s/1APiyo22_EKd3Y9SKYpwl7A">这里</a>(提取码:m33b)直接进行下载</p></li><li class="lvl-2"><p>将 <code>gradlegradle-6.1.1-all.zip(或者其他版本名字)</code> 下载完成之后放着待用</p></li><li class="lvl-2"><p>在你的c盘中找到该路径 <code>C:\Users\你的用户名\.gradle\wrapper\dists\gradle-6.1.1-all(或者其他版本名字)\cfmwm155h49vnt3hynmlrsdst</code></p></li><li class="lvl-2"><p>将其中的文件全部删除,再把刚刚下载好的文件粘贴进去</p></li><li class="lvl-2"><p>重启 Android Studio,此时会自动跳过下载并开始解压i</p></li></ul><h2 id="2-给-Button-添加背景之后不显示">2.给 Button 添加背景之后不显示</h2><ul class="lvl-0"><li class="lvl-2"><p>添加背景后依然显示默认颜色,此时需要给布局处加入以下这一行</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xmlns:app="http://schemas.android.com/apk/res-auto"</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>然后在按钮的设置处加入以下这行</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">app:backgroundTint="@null" </span><br></pre></td></tr></table></figure><h2 id="3-如何修改AS的模拟器位置">3.如何修改AS的模拟器位置</h2><ul class="lvl-0"><li class="lvl-2"><p>在 <code>C:\user\用户名\.android\avd</code> 或 <code>C:\Android\.android\avd</code> 中找到模拟器文件夹,一个文件夹对应一个配置文件</p></li><li class="lvl-2"><p>将模拟器文件夹移动到你所需要移动到的位置,我这里移动到了这里:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">D:\Android\avd\Pixel_3a_API_30_x86.avd</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>修改C盘的配置文件中的path字段即可,如下:</p></li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">avd.ini.encoding=UTF-8</span><br><span class="line">path=D:\Android\avd\Pixel_3a_API_30_x86.avd</span><br><span class="line">path.rel=avd\Pixel_3a_API_30_x86.avd</span><br><span class="line">target=android-30</span><br></pre></td></tr></table></figure><ul class="lvl-0"><li class="lvl-2"><p>打开AS测试模拟器是否可以正常运行</p></li></ul><h2 id="4-如何修改Android项目的包名">4.如何修改Android项目的包名</h2><blockquote><p>当你引用别人的项目时,会发现包名是别人的包名,想要修改成为自己的包名按以下操作即可</p></blockquote><ul class="lvl-0"><li class="lvl-2"><p>建议在Project格式下,找到 <code>app/src/main/java</code> 路径,在这之下就是项目的包名,点击右上角的齿轮图标,如下图:<br><img src="https://s3.ax1x.com/2020/12/14/rnIKnx.png" alt="Android03.png"></p></li><li class="lvl-2"><p>将 <strong>Compact Middle Packages</strong> 选项取消勾选,更改后如下图:<br><img src="https://s3.ax1x.com/2020/12/14/rnIY3d.png" alt="Android04.png"></p></li><li class="lvl-2"><p>点击你需要更改的包名,按快捷键 <strong>shift + F6</strong> 进行重命名操作,并选择 <strong>Rename package</strong>,如下图:<br><img src="https://s3.ax1x.com/2020/12/14/rnIBE8.png" alt="Android05.png"></p></li><li class="lvl-2"><p>填好包名后点击 <strong>Refactor</strong>,此时下方会弹出小框提示哪些文件需要一并修改,这里AS会自动检测并帮我们自动修改,点击 <strong>Do Refactor</strong>,如下图:<br><img src="https://s3.ax1x.com/2020/12/14/rnIfbV.png" alt="Android06.png"></p></li><li class="lvl-2"><p>完成后修改 app 目录下的 <code>build.gradle</code> 文件中的 applicationId 字样,成功后点击 <strong>Sync now</strong> 修改完成,如下图:<br><img src="https://s3.ax1x.com/2020/12/14/rnI78J.png" alt="Android07.png"></p></li><li class="lvl-2"><p><a target="_blank" rel="external nofollow noopener noreferrer" href="https://www.jianshu.com/p/14d92eecfada">https://www.jianshu.com/p/14d92eecfada</a></p></li><li class="lvl-2"><p>双击返回键退出应用:<a target="_blank" rel="external nofollow noopener noreferrer" href="https://blog.csdn.net/qq_23179075/article/details/60587202">https://blog.csdn.net/qq_23179075/article/details/60587202</a></p></li><li class="lvl-2"><p>实现沉浸式状态栏:<a target="_blank" rel="external nofollow noopener noreferrer" href="https://blog.csdn.net/weixin_43796132/article/details/102250632">https://blog.csdn.net/weixin_43796132/article/details/102250632</a></p></li></ul></div><footer class="post-footer"><div class="my_post_copyright"><script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script><script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script><script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script><p><span>本文标题:</span><a href="/Angular-Basics.html">学习笔记:Android</a></p><p><span>文章作者:</span><a href="/" title="访问 Zhang Yangeng 的个人博客">Zhang Yangeng</a></p><p><span>发布时间:</span>2020年08月31日 - 08:08</p><p><span>最后更新:</span>2023年01月31日 - 18:01</p><p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a></p><p><span>注意事项:</span>转载请保留原文链接及作者,请尊重作者的劳动成果</p><p><span>原始链接:</span><a href="/Angular-Basics.html" title="学习笔记:Android">https://www.wrysmile.cn/Angular-Basics.html</a> <span class="copy-path" title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://www.wrysmile.cn/Angular-Basics.html" aria-label="复制成功!"></i></span></p></div><script>var clipboard=new Clipboard(".fa-clipboard");$(".fa-clipboard").click(function(){clipboard.on("success",function(){swal({title:"",text:"复制成功",icon:"success",showConfirmButton:!0})})})</script><div class="reward-container"><div>坚持原创技术分享,您的支持将是对我最大的鼓励!</div><button onclick='document.querySelector(".post-reward").classList.toggle("active")'>赞赏</button><div class="post-reward"><div><img src="https://s2.ax1x.com/2019/01/28/kKrX7T.png" alt="Zhang Yangeng 微信"> <span>微信</span></div><div><img src="https://i.loli.net/2019/01/25/5c4ac75f2e5b7.jpg" alt="Zhang Yangeng 支付宝"> <span>支付宝</span></div></div></div><div class="post-tags"><a href="/tags/Android/" rel="tag"><i class="fa fa-tag"></i> Android</a></div><div class="post-nav"><div class="post-nav-item"><a href="/Input.html" rel="prev" title="玩机:巧妙备份并转换输入法词库"><i class="fa fa-chevron-left"></i> 玩机:巧妙备份并转换输入法词库</a></div><div class="post-nav-item"><a href="/ShortcutKey.html" rel="next" title="强烈推荐:快捷键集合">强烈推荐:快捷键集合 <i class="fa fa-chevron-right"></i></a></div></div></footer></article></div><div class="comments" id="lv-container" data-id="city" data-uid="MTAyMC80MjQ5Ni8xOTA0Mw=="></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright">© 2019 – <span itemprop="copyrightYear">2023</span> <span class="with-love"><i class="fa fa-heart"></i> </span><span class="author" itemprop="copyrightHolder">Wrysmile</span></div><div class="wordcount"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-chart-line"></i> </span><span>站点总字数:</span> <span title="站点总字数">413k</span> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-coffee"></i> </span><span>站点阅读时长 ≈</span> <span title="站点阅读时长">6:15</span></span></div><div class="busuanzi-count"><span class="post-meta-item" id="busuanzi_container_site_uv"><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span> </span></span><span class="post-meta-item" id="busuanzi_container_site_pv"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div><script color="0,0,255" opacity="0.5" zindex="-1" count="99" src="https://cdn.jsdelivr.net/npm/canvas-nest.js@1/dist/canvas-nest.js"></script><script type="text/javascript">!function(e,r){function t(){for(var e=0;e<n.length;e++)n[e].alpha<=0?(r.body.removeChild(n[e].el),n.splice(e,1)):(n[e].y--,n[e].scale+=.004,n[e].alpha-=.013,n[e].el.style.cssText="left:"+n[e].x+"px;top:"+n[e].y+"px;opacity:"+n[e].alpha+";transform:scale("+n[e].scale+","+n[e].scale+") rotate(45deg);background:"+n[e].color+";z-index:99999");requestAnimationFrame(t)}var o,n=[];e.requestAnimationFrame=e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)},function(t){var a=r.createElement("style");a.type="text/css";try{a.appendChild(r.createTextNode(t))}catch(e){a.styleSheet.cssText=t}r.getElementsByTagName("head")[0].appendChild(a)}(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o="function"==typeof e.onclick&&e.onclick,e.onclick=function(e){var t,a;o&&o(),t=e,(a=r.createElement("div")).className="heart",n.push({el:a,x:t.clientX-5,y:t.clientY-5,scale:1,alpha:1,color:"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}),r.body.appendChild(a)},t()}(window,document)</script><script type="text/javascript">var titleTime,OriginTitle=document.title;document.addEventListener("visibilitychange",function(){document.hidden?($('[rel="icon"]').attr("href","/img/TEP.ico"),document.title="╭(°A°`)╮ 页面崩溃啦 ~",clearTimeout(titleTime)):($('[rel="icon"]').attr("href","/favicon.ico"),document.title="(ฅ>ω<*ฅ) 噫又好了~"+OriginTitle,titleTime=setTimeout(function(){document.title=OriginTitle},2e3))})</script></div></footer><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/jquery.fancybox.min.js" integrity="sha256-yt2kYMy0w8AbtF89WXb2P1rfjcP/HTHLT7097U8Y5b8=" crossorigin="anonymous"></script><script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script src="/js/third-party/search/local-search.js"></script><script class="next-config" data-name="nprogress" type="application/json">{"enable":true,"spinner":false}</script><script src="/js/third-party/nprogress.js"></script><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><script class="next-config" data-name="leancloud_visitors" type="application/json">{"enable":true,"app_id":"mzhbgeWR9BA3SvqtvaAJulC1-gzGzoHsz","app_key":"xcGndtx2gmyop5yrT6euUk9G","server_url":null,"security":false}</script><script src="/js/third-party/statistics/lean-analytics.js"></script><script src="/js/third-party/comments/livere.js"></script></body></html>