第一行代码-第二版(郭霖著)笔记十一(Material Design)

article/2025/9/17 8:15:25

目录

一、什么是Material Design

二、Toolbar

三、滑动菜单

1.DrawerLayout

2.NavigationView

四、悬浮按钮和可交互提示

1.FloatingActionButton:悬浮按钮

2.Snackbar:提示工具

3.CoordinatorLayout:加强版FrameLayout

五、卡片式布局

1.MaterialCardView

2.AppBarLayout

六、下拉刷新

七、可折叠式标题栏

1.CollapsingToorbarLayout

2.充分利用系统状态栏空间


一、什么是Material Design

一套全新的界面设计语言

二、Toolbar

修改D:\soft\projects\MaterialTest\app\src\main\res\values\themes.xml

//界面的主体颜色设成深色,陪衬颜色设成淡色
<style name="Theme.MaterialTest" parent="Theme.MaterialComponents.NoActionBar">


//界面的主体颜色设成淡色,陪衬颜色设成深色
<style name="Theme.MaterialTest" parent="Theme.MaterialComponents.Light.NoActionBar">


 

如何使用Toolbar?

 首先修改themes.xml文件:

<resources xmlns:tools="http://schemas.android.com/tools"><!-- Base application theme. --><style name="Theme.MaterialTest" parent="Theme.MaterialComponents.Light.NoActionBar"><!-- Primary brand color. --><item name="colorPrimary">@color/purple_500</item><item name="colorPrimaryVariant">@color/purple_700</item><item name="colorOnPrimary">@color/white</item><!-- Secondary brand color. --><item name="colorSecondary">@color/teal_200</item><item name="colorSecondaryVariant">@color/teal_700</item><item name="colorOnSecondary">@color/black</item><!-- Status bar color. --><item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item><!-- Customize your theme here. --></style>
</resources>

其次在activity_main.xml添加:

<androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="@color/purple_500"tools:ignore="MissingConstraints" />

 最后修改MainActivity:

public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Toolbar toolbar = findViewById(R.id.toolbar);setSupportActionBar(toolbar);}
}

效果如下图:

 

添加android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"让Toolbar单独使用深色主题,这样文字就会变成浅色,如下图

<androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="@color/purple_500"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"tools:ignore="MissingConstraints" />

 

在Toolbar中添加一些按钮

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"><itemandroid:id="@+id/backup"android:title="Backup"android:icon="@drawable/ic_backup"app:showAsAction="always"/><itemandroid:id="@+id/delete"android:title="Delete"android:icon="@drawable/ic_delete"app:showAsAction="ifRoom"/><itemandroid:id="@+id/settings"android:title="Settings"android:icon="@drawable/ic_settings"app:showAsAction="never"/>
</menu>
public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Toolbar toolbar = findViewById(R.id.toolbar);setSupportActionBar(toolbar);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.toolbar,menu);return true;}@Overridepublic boolean onOptionsItemSelected(@NonNull MenuItem item) {switch (item.getItemId()){case R.id.backup:Toast.makeText(this, "你点击了返回", Toast.LENGTH_SHORT).show();break;case R.id.delete:Toast.makeText(this, "你点击了删除", Toast.LENGTH_SHORT).show();break;case R.id.settings:Toast.makeText(this, "你点击了设置", Toast.LENGTH_SHORT).show();break;default:}return true;}
}

如果不指定android:icon="@drawable/ic_backup",会用title作为按钮,如下图:

 加了icon属性如下图:

 当你点最右边三个点时如下图:

 只需要在布局文件中的Toolbar添加如下代码就可以,如下图:

app:popupTheme="@style/Theme.AppCompat.Light"

 


三、滑动菜单

1.DrawerLayout

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/drawer_layout"android:layout_height="match_parent"android:layout_width="match_parent"><FrameLayout android:layout_width="match_parent"android:layout_height="match_parent"><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="@color/colorPrimary"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /></FrameLayout>
<!--指定start表示会根据系统语言进行判断,系统语言是从左往右的,滑动菜单在左边,系统语言从右往左的,滑动菜单在右边--><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"  android:layout_gravity="start"android:text="这是菜单"android:textSize="30sp"android:background="#FFF"/></androidx.drawerlayout.widget.DrawerLayout>


Toorbar的最左边加入一个导航按钮

public class MainActivity extends AppCompatActivity {private DrawerLayout drawerLayout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Toolbar toolbar = findViewById(R.id.toolbar);setSupportActionBar(toolbar);drawerLayout = findViewById(R.id.drawer_layout);ActionBar actionBar = getSupportActionBar();if(actionBar!=null){//让导航按钮显示出来actionBar.setDisplayHomeAsUpEnabled(true);//设置导航按钮图标actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.toolbar,menu);return true;}@Overridepublic boolean onOptionsItemSelected(@NonNull MenuItem item) {switch (item.getItemId()){//HomeAsUp按钮的id永远都是android.R.id.homecase android.R.id.home:drawerLayout.openDrawer(GravityCompat.START);break;case R.id.backup:Toast.makeText(this, "你点击了返回", Toast.LENGTH_SHORT).show();break;case R.id.delete:Toast.makeText(this, "你点击了删除", Toast.LENGTH_SHORT).show();break;case R.id.settings:Toast.makeText(this, "你点击了设置", Toast.LENGTH_SHORT).show();break;default:}return true;}
}

2.NavigationView

添加依赖:

//开源项目CircleImageView,可以用来轻松实现图片圆形化的功能
implementation 'de.hdodenhof:circleimageview:3.1.0'

 NavigationView不用添加依赖,直接

<com.google.android.material.navigation.NavigationViewandroid:id="@+id/nav_view"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="start"app:menu="@menu/nav_menu"app:headerLayout="@layout/nav_header"/>


四、悬浮按钮和可交互提示

1.FloatingActionButton:悬浮按钮

<com.google.android.material.floatingactionbutton.FloatingActionButtonandroid:id="@+id/fab"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="bottom|end"android:layout_margin="16dp"android:src="@drawable/ic_done"//指定高度值,高度值越大,投影范围也越大,投影效果越淡;高度值越小,投影范围越小,投影效果越浓app:elevation="8dp"/>


2.Snackbar:提示工具

Snackbar允许在提示中加入一个可交互按钮

FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//第一个参数需要传入一个View,当前界面布局的任意一个View都可以;第二个参数是内容;第三个参数是显示的时长Snackbar.make(v,"数据删除",Snackbar.LENGTH_SHORT).setAction("不做", new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "数据保存", Toast.LENGTH_SHORT).show();}}).show();}
});


3.CoordinatorLayout:加强版FrameLayout

CoordinatorLayout可以监听其所有子控件的各种事件,然后自动帮助我们做出最为合理的响应。

比如可以实现提示条不会挡住悬浮按钮

<androidx.coordinatorlayout.widget.CoordinatorLayout 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=".MainActivity"><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorOnSecondary"android:theme="@style/ThemeToolbar"app:titleTextColor="@color/white"/><com.google.android.material.floatingactionbutton.FloatingActionButtonandroid:id="@+id/fab"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="bottom|end"android:layout_margin="16dp"android:src="@drawable/ic_done"app:elevation="8dp"/></androidx.coordinatorlayout.widget.CoordinatorLayout>


五、卡片式布局

1.MaterialCardView

也是一个FrameView,只是额外提供了圆角和阴影等效果

添加Glide库依赖:Glide是一个超级强大的图片加载库

implementation 'com.github.bumptech.glide:glide:4.12.0'
<com.google.android.material.card.MaterialCardViewandroid:layout_width="match_parent"android:layout_height="wrap_content"app:cardCornerRadius="4dp"app:elevation="5dp"><TextViewandroid:id="@+id/infoText"android:layout_width="match_parent"android:layout_height="wrap_content"/>
</com.google.android.material.card.MaterialCardView>

 

2.AppBarLayout

实际上是一个垂直方向的LinearLayout,在内部做了很多滚动事件的封装

怎么解决Toolbar被覆盖的问题?

第一步将Toolbar嵌套到AppBarLayout中,第二部给RecycleView指定一个布局行为

<com.google.android.material.appbar.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorOnSecondary"android:theme="@style/ThemeToolbar"app:titleTextColor="@color/white"/>
</com.google.android.material.appbar.AppBarLayout><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recycle_view"android:layout_width="match_parent"android:layout_height="match_parent"//指定一个布局行为app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<com.google.android.material.appbar.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorOnSecondary"android:theme="@style/ThemeToolbar"app:titleTextColor="@color/white"//scroll表示当RecycleView向上滚动时,Toolbar会跟着一起向上滚动并隐藏;enterAlways反之;snap表示当Toolbar还没有完全隐藏或显示的时候,会根据当前的滚动距离,自动选择是隐藏还是显示app:layout_scrollFlags="scroll|enterAlways|snap"/>
</com.google.android.material.appbar.AppBarLayout><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recycle_view"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

六、下拉刷新

SwipeRefreshLayout是用于实现下拉刷新功能的核心类

导入SwipeRefreshLayout依赖:

implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

在RecycleView的外面嵌套一层SwipeRefreshLayout,这样RecycleView就自动拥有下拉刷新的功能了:

<androidx.swiperefreshlayout.widget.SwipeRefreshLayoutandroid:id="@+id/swipe_refresh"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_scrolling_view_behavior"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recycle_view"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

修改MainActivity:

    protected void onCreate(Bundle savedInstanceState) {......swipeRefreshLayout  = findViewById(R.id.swipe_refresh);
//        swipeRefreshLayout.setColorSchemeResources(R.color.design_default_color_primary);swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {@Overridepublic void onRefresh() {refreshFruits();}});}private void refreshFruits(){new Thread(new Runnable() {@Overridepublic void run() {try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}runOnUiThread(new Runnable() {@Overridepublic void run() {initFruits();//通知数据发生了变化adapter.notifyDataSetChanged();//表示刷新事件结束,并隐藏刷新进度条swipeRefreshLayout.setRefreshing(false);}});}}).start();}

七、可折叠式标题栏

1.CollapsingToorbarLayout

一个作用于Toolbar基础之上的布局,可以让Toolbar的效果变得更加丰富,展示标题栏的同时实现非常华丽的效果。CollapsingToolbarLayout只能作为AppBarLayout的直接子布局来使用,而AppBarLayout又必须是CoordinatorLayout的子布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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=".FruitActivity"android:fitsSystemWindows="true"><com.google.android.material.appbar.AppBarLayoutandroid:id="@+id/appBar"android:layout_width="match_parent"android:layout_height="250dp"android:fitsSystemWindows="true"><com.google.android.material.appbar.CollapsingToolbarLayoutandroid:id="@+id/collapsing_toorbar"android:layout_width="match_parent"android:layout_height="match_parent"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"//指定CollapsingToolbarLayout趋于折叠状态以及折叠之后的背景色app:contentScrim="@color/black"scroll表示CollapsingToolbarLayout会对着水果内容详情的滚动一起滚动,exitUntilCollapsed表示当CollapsingToolbarLayout随着滚动完成折叠之后就保留在界面上,不再移出屏幕app:layout_scrollFlags="scroll|exitUntilCollapsed"android:fitsSystemWindows="true"><ImageViewandroid:id="@+id/fruit_image_view"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="centerCrop"//折叠模式parallax:在折叠过程中产生一定的错位偏移app:layout_collapseMode="parallax"android:fitsSystemWindows="true"/><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"//折叠模式pin:在折叠的过程中位置始终保持不变app:layout_collapseMode="pin"/></com.google.android.material.appbar.CollapsingToolbarLayout></com.google.android.material.appbar.AppBarLayout>//允许使用滚动的方式来查看屏幕以外的数据,并增加了嵌套响应滚动事件的功能 内部只允许存在一个直接子布局,如果想要在里面放入很多东西,通常会先嵌套一个LinearLayout<androidx.core.widget.NestedScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_scrolling_view_behavior"><LinearLayoutandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><androidx.cardview.widget.CardViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="35dp"android:layout_marginLeft="15dp"android:layout_marginRight="15dp"android:layout_marginBottom="15dp"app:cardCornerRadius="4dp"><TextViewandroid:id="@+id/fruit_content_text"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="10dp"/></androidx.cardview.widget.CardView></LinearLayout></androidx.core.widget.NestedScrollView><com.google.android.material.floatingactionbutton.FloatingActionButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="16dp"android:src="@drawable/ic_comment"//指定了一个锚点,锚点设置为AppBarLayout,这样悬浮按钮就会出现在水果标题栏的区域内app:layout_anchor="@id/appBar"//将悬浮按钮定位在标题栏区域的右下角app:layout_anchorGravity="bottom|end"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

2.充分利用系统状态栏空间

第一步:将ImageView和ImageView布局的所有父布局都设置上下面的属性

android:fitsSystemWindows="true"

第二步:打开res/values/styles.xml文件,对主题的内容进行修改

<resources><!-- Base application theme. --><style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"><!-- Customize your theme here. --><item name="colorPrimary">@color/colorPrimary</item><item name="colorPrimaryDark">@color/colorPrimaryDark</item><item name="colorAccent">@color/colorAccent</item></style><style name="FruitActivityTheme" parent="AppTheme"><item name="android:statusBarColor">@android:color/transparent</item></style>
</resources>

 最后,还需要让FruitActivity使用这个主题才可以

<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.materialtest"><applicationandroid: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">...<activityandroid:name=".FruitActivity"android:theme="@style/FruitActivityTheme"></activity></application>
</manifest>

完!


http://chatgpt.dhexx.cn/article/pbaetNme.shtml

相关文章

第一行代码-第二版(郭霖著)笔记二(Activity)

目录 一、Activity的用法 1.Activity 2.Toast 3.菜单 4.销毁一个活动 二、Intent 1.使用显示Intent 2.使用隐式Intent 3.更多隐式Intent的用法 4.向下一个活动传递数据 5.返回数据给上一个活动 三、活动的生命周期 1.返回栈 2.活动的四种状态 3.活动的生存期 4…

android动态权限依赖库,动态申请app权限:郭霖大神的PermissionX库带你告别原生

引言 为什么那么多人想要自定义Android的权限申请PermissonX?因为PermissionX默认的权限提醒弹出实在是太丑了!而且,需要在你需要提醒用户弹出Dialog时,显得捉襟见肘,你可能就在想有没有一款能封装进去Dialog提醒用户,具有超棒的用户体验,还能看起来美观大气的Permissio…

跟随郭霖学Volley

volley 下载导入volleyjar 学习地址: https://blog.csdn.net/guolin_blog/article/details/17482095 2013在Google I/O大会提出 github地址: https://github.com/google/volley 下载volley导入到as 具体的操作是: project模式下 具体看图: 之后的操作是打开lib 选择jar 右…

android 6.0权限 郭霖,Permission——郭霖认为最优的运行时权限方案

Android6.0发布这么久&#xff0c;对运行时权限也看了很多资料&#xff0c;对比过几个流行的库。但是个人还是喜欢在项目里用自己动手封装的东西&#xff0c;哪怕照抄也好。。。不知道是什么原因。 前天无意听郭神的直播。讲解的是运行时权限的封装&#xff0c;收益颇多。依样画…

郭霖LitePal

由于项目需要开始学习sqlite 一开始先学习使用的是 android ormlite 操作 从最基本的建表增删改查一路走来 磕磕碰碰很多 都是在内存中操作sqlite 只能通过sqlitestudio工具进行查看 不能导出 并且应用卸载数据表就丢失 最终考虑在sd卡中操作sqlite 但是ormlite 并没有这方面…

android郭霖博客,Runtime Permissions(郭霖CSDN公开课)

运行时权限 Api23开始&#xff0c;Android权限机制更改&#xff0c;有一部分权限不再是简单的在AndroidManifest.xml中声明即可。而是需要在运行时让用户去选择是否允许该项权限的操作。 那么哪些权限需要在运行时申请呢&#xff1f;危险权限需要这么做&#xff0c;而普通权限仍…

看一看Facebook工程师是怎么评价《第一行代码》的

本文同步发表于我的微信公众号&#xff0c;扫一扫文章底部的二维码或在微信搜索 郭霖 即可关注&#xff0c;每个工作日都有文章更新。 大家好&#xff0c;我是一名Facebook的工程师&#xff0c;同时也是《第一行代码——Android》的忠实读者。 虽然我最近几年是在国外读书和工…

郭霖:手把手教你实现 App 360 度旋转看车效果

这是郭神号前阵子的推送&#xff0c;应该有不少人还没有看过&#xff0c;现在分享给大家&#xff0c;希望对大家的Android工作和学习有所帮助。 / 作者简介 / 本篇文章来自Youth Lee的投稿&#xff0c;分享了他自己结合Glide写的一个控件&#xff0c;希望对大家有所帮助&#…

第一行代码-第二版(郭霖著)笔记(初识Android)

系列文章目录 第一章 第一行代码-第二版&#xff08;郭霖著&#xff09;笔记&#xff08;初识Android&#xff09; 目录 一、Android简介 1.android系统架构 2.Android应用开发特色 二、工具准备 Tips:新建项目的时候是否勾选use legacy android.support libraries 三、…

专访郭霖:成长无止境

留意文末赠书活动 嘉宾 | 郭霖 文 | 张霞 郭霖&#xff0c;Android开发工程师&#xff0c;Android GDE&#xff08;Google认证开发者专家&#xff09;。从事Android开发工作9年&#xff0c;有着丰富的项目实战经验&#xff0c;负责及参与开发过多款移动应用与游戏&#xff0c;开…

解决http响应状态为canceled

最近写登录的页面&#xff0c;发现通过ajax请求后台的时候&#xff0c;监控台返回该请求的状态是canceled。 原因 仅仅是由于之前为了在输入账号时让浏览器进行自动补全&#xff0c;而将原先的div更换为了form,而不巧的是之前的登录事件源使用的是button。 而至于为什么stat…

ajax请求导致status为canceled的原因

在使用layui的form表单提交以后&#xff0c;请求状态总是canceled。后来在form表单的后面添加了一行代码&#xff1a; return false; 就可以了。 文档&#xff1a;https://www.layui.com/doc/modules/form.html#onsubmit 错误&#xff1a; 解决方法&#xff1a; 总结一下&…

ajax请求文件状态为 canceled 的解决办法

ajax请求文件状态为 canceled 的解决办法 场景还原原因分析解决 场景还原 最近做一个表单提交的需求时&#xff0c;遇到了这种情况&#xff0c;输完账号密码后回车提交&#xff0c;报错&#xff0c;f12打开看到是请求的status为canceled了&#xff0c;震惊一秒钟。。。如下图&…

chrome同步或登录报错:Request Canceled

原因 因为某个接口连接失败造成&#xff0c;可以摁快捷键F12或者点击开发者工具。 然后选择network&#xff0c;这里面是该页面所有的收发请求 开始登录&#xff0c;登录的时候要注意network中pending或者报错的接口&#xff0c;然后把域名记录下来 解决方式 安装chrome插…

http发送请求,status显示canceled的原因

原因&#xff1a;onSubmit和submit属性比较陈旧&#xff0c;在提交了数据以后会自动刷新页面&#xff0c;导致信息丢失以及请求中止 解决&#xff1a;在 handler里面写入e.preventDefault();阻止onsubmit执行默认的刷新页面行为。

使用 npm create vue@3 报错 npm ERR! canceled

问题 之前运行都可以成功创建&#xff0c;但今天运行 npm create vue3 的时候报错了&#xff0c;错误信息如下&#xff1a; 解决方法 在网上找了一堆方法都无效。 npm 版本问题&#xff0c;升级到最新版本 npm i -g npm&#xff0c;然后重试 npm create vue3 【x】npm cac…

Go:read一个已经被canceled的http.Request的应答

Go&#xff1a;read一个已经被canceled的http.Request的应答 1.复现 最近发现项目在处理chunk类型的http应答时&#xff0c;出现读数据异常报错&#xff0c;代码示例如下&#xff1a; server package mainimport ("bytes""net/http" )func main() {http…

Idea通过git拉取代码的时候出现Update canceled问题

当在IDEA中通过Git更新代码时&#xff0c;拉取失败&#xff0c;报如下错误 12:31 Update failedInvocation failed Server returned invalid Response.java.lang.RuntimeException: Invocation failed Server returned invalid Response.at git4idea.GitAppUtil.sendXmlRequest…

Xmodem operation was canceled by remote peer问题已解决

1.Xmodem operation was canceled by remote peer. 传输的时候就会出现注意的问题 2.使用df -h命令查看内存状况&#xff0c;可以发现root已经满了。 3.进入根目录&#xff0c;ls显示&#xff0c;使用rm命名将其中的文件删除 4.显示&#xff0c;可以看见内存占用变少。 5.…

vue proxy发出的post请求出现超时导致的canceled

0 问题 vue的proxy代理好了之后&#xff0c;get请求没问题&#xff0c;post请求出现canceled&#xff0c;如下图所示&#xff1a; 解决方案 参考 https://github.com/chimurai/http-proxy-middleware/issues/40 devServer: {host: 0.0.0.0,port: 8085,proxy: {/api: {targ…