开发常用笔记
1.Fragment布局上面留出一小块的空白
使用AppBarLayout的标题自动上拉动画,但是启动了含有AppBarLaout的布局后,其他Fragemnt的布局上面就会有一小块的空白留着,后来发现是这个
android:fitsSystemWindows="true"参数的原因,把它注销掉解决
2.Android之AutoCompleteTextView用法详解,
可设置下拉提示
待研究:
1.Fragment向aCTIVITY跳转,同时Activity返回Fragment携带参数(回调),不同Activity的Fragment之间跳转可以使用NVIHostFragment吗
2.重写ActionBar实现上面的标题栏有搜索、返回等效果
3.约束布局ConstraintLayout使用
https://www.jianshu.com/p/17ec9bd6ca8a
4.设置图片不失真的放大填充,不能用其他空间imagebutton,textview,只能使用imageview
<ImageView
android:id="@+id/tool1"
android:layout_width="350dp"//设置一个固定宽度
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:src="@mipmap/tools01" //背景使用src引用
android:layout_gravity="center"
android:scaleType="fitCenter" //设置展示方式
android:adjustViewBounds="true" //设置自适应参数true(必须设置maxHeight,maxwidth两个参数,要不然这个设置不生效)
android:maxHeight="150dp"
android:maxWidth="350dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"></ImageView>
5.Demo合集
https://github.com/alidili/Demos
6.带阴影的drawble
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 阴影部分 -->
<!-- 个人觉得更形象的表达:top代表下边的阴影高度,left代表右边的阴影宽度。其实也就是相对应的offset,solid中的颜色是阴影的颜色,也可以设置角度等等 -->
<item
android:right="10dp"
android:top="4dp">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#0F000000"
android:startColor="#0F000000" />
<corners
android:bottomLeftRadius="14dp"
android:bottomRightRadius="14dp"
android:topLeftRadius="14dp"
android:topRightRadius="14dp" />
</shape>
</item>
<!-- 背景部分 -->
<!-- 形象的表达:bottom代表背景部分在上边缘超出阴影的高度,right代表背景部分在左边超出阴影的宽度(相对应的offset) -->
<item
android:bottom="3dp"
android:left="3dp"
android:top="0.5dp"
android:right="0.5dp">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#FFFFFF"
android:startColor="#FFFFFF" />
<corners
android:bottomLeftRadius="14dp"
android:bottomRightRadius="14dp"
android:topLeftRadius="14dp"
android:topRightRadius="14dp" />
<!-- <stroke android:color="@color/grey" android:width="0.5dip"></stroke>-->
</shape>
</item>
</layer-list>
7.设置颜色
textcolor: color/text_color_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FFF" android:state_checked="false" />
<item android:color="#000" android:state_checked="true" />
</selector>
8.设置背景drawble
<?xml version="1.0" encoding="utf-8"?>
selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue_button_background_checked" android:state_pressed="true"/>
<item android:drawable="@drawable/blue_button_background_checked" android:state_selected="true"/>
<item android:drawable="@drawable/blue_button_background_checked" android:state_checked="true"/>
<item android:drawable="@drawable/blue_button_background_unchecked"/>
</selector>
unchecked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@color/darkblue" />
<!-- 边缘线条颜色 -->
<!-- <stroke-->
<!-- android:width="1dp"-->
<!-- android:color="@color/black" />-->
<!-- 圆角的幅度 -->
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp" />
</shape>
8.<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="10dp"
card_view:cardBackgroundColor="@color/cardviewback"
app:cardBackgroundColor="@color/grey"
card_view:cardElevation="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
card_view:contentPaddingTop="10dp"
card_view:contentPaddingBottom="10dp">
</androidx.cardview.widget.CardView>
cardview不能放在xml根目录下,同时必须包含上面的xmlns:引用
9.上滑显示标题
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/white"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<!--顶部定位布局-->
<include layout="@layout/index_naigator_up_layout"></include>
<!--顶部定位布局-->
<!--中间菜单栏-->
<include layout="@layout/home_menu_layout"></include>
<!--中间菜单栏-->
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<!--我的课表-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="25dp"
android:orientation="vertical">
<TextView
style="@style/text_class_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我的课表"></TextView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/today"
style="@style/text_class_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="@drawable/text_date_back_pressed"
android:clickable="true"
android:focusable="true"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:text="今天"></TextView>
<TextView
android:id="@+id/tommorrow"
style="@style/text_class_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="@drawable/text_date_back"
android:clickable="true"
android:focusable="true"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:text="明天"></TextView>
<TextView
android:id="@+id/more"
style="@style/text_class_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="@drawable/text_date_back"
android:clickable="true"
android:focusable="true"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:text="查询更多"></TextView>
</LinearLayout>
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="always"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray"
android:focusableInTouchMode="true"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/course"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_marginTop="10dp"
android:visibility="visible"></androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<!--我的课表-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
10.BottomNavifationView
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:itemHorizontalTranslationEnabled="false"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu"
/>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="50dp"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
去掉点击菜单导航栏字体消失需要加上navView.setLabelVisibilityMode(1);这句
初始化:
@SuppressLint("WrongConstant")
private void initNavigatorView() {
BottomNavigationView navView = findViewById(R.id.nav_view);
navView.setLabelVisibilityMode(1);
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
// NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
}
不用Actionbar的话需要设置noActionBar属性,同时注销掉 NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
Fragment传值
Bundle mbudle=new Bundle();
mbudle.putString("systemalramjson", JSON.toJSONString(mArticalbean));
Navigation.findNavController(view).navigate(R.id.navigation_system_detail,mbudle);
if (getArguments() != null) {
String jsondetail = getArguments().getString("systemalramjson");
AriticalBean martical = new Gson().fromJson(jsondetail, AriticalBean.class);
}
10.启动Fragment
private void startFragment(Fragment fragment){
fragmentManager =getSupportFragmentManager();
// 2.开启一个事务,通过调用beginTransaction()方法开启
transaction = fragmentManager.beginTransaction();
// 3.向容器内添加或替换碎片,一般使用replace()方法实现,需要传入容器的id和待添加的碎片实例
transaction.replace(R.id.fr_container, fragment); //fr_container不能为fragment布局,可使用线性布局相对布局等。
// 4.使用addToBackStack()方法,将事务添加到返回栈中,填入的是用于描述返回栈的一个名字
transaction.addToBackStack(null);
// 5.提交事物,调用commit()方法来完成
transaction.commit();
}
11.推到后台继续播放
// moveTaskToBack(true);
//
// Intent i = new Intent(Intent.ACTION_MAIN);
// // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //如果是服务里调用,必须加入new task标识
// i.addCategory(Intent.CATEGORY_HOME);
// startActivity(i);
12.枚举的使用:
https://www.cnblogs.com/happyPawpaw/archive/2013/04/09/3009553.html
13.使用setStatusBar()设置状态栏透明并且全屏显示后,发现上面带一个白色的状态栏,好像没有透明一样,原因竟然是xml中根布局中加了android:fitsSystemWindows="true",去掉就可以了
private void setStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
private void setStatusBarTrans(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
// | View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
13.在设置了全屏显示的页面上,标题容易和上面的状态栏重合,
1.activity
需要设置一个参数就可以android:fitsSystemWindows="true",同时设置高度为android:layout_height="?android:actionBarSize"
2.Fragment:
//设置沉浸式状态栏后会出现上面标题栏和状态栏重叠的问题,Activity可以在标题栏的根布局那里加android:fitsSystemWindows="true"
Fragment设置它所在的Activity布局就会变成状态栏出来,而且不是透明的了,
//但是xml这样设置了就不会生效,如果在aciitvity的根布局上设置了这个属性还会导致透明状态栏变为有色的,
// 所以要根据不同的状态栏高度设置padding值
https://blog.csdn.net/xiyangyang8110/article/details/80183892
Android沉浸式实现(完美版:布局内容不会与状态栏重叠)
@BindView(R.id.toolbarview)
ConstraintLayout toolbarview;
setImmerseLayout(toolbarview);
protected void setImmerseLayout(View view) {// view为标题栏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
int statusBarHeight = getStatusBarHeight(getActivity().getBaseContext());
view.setPadding(0, statusBarHeight, 0, 0);
}
}
public int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
标题栏xml
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolbarview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:actionBarSize"
android:background="@color/buttongrey"
android:layout_gravity="center_vertical"
>
<ImageButton
android:id="@+id/returnview"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="15dp"
android:background="@drawable/ic_return"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"></ImageButton>
<TextView
android:id="@+id/title"
style="@style/text_tool_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="个人资料"
android:gravity="center_vertical"
android:layout_marginBottom="15dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"></TextView>
</androidx.constraintlayout.widget.ConstraintLayout>
14.android全屏/沉浸式状态栏下,各种键盘挡住输入框解决办法
https://blog.csdn.net/smileiam/article/details/69055963
15、Fragment生命周期
onAttach()-onCreate- onCreateView-onActivityCreated-onStart()-onResume-onPause-
fragment的生命周期及两种适配器的区别
https://www.jianshu.com/p/82742710fc5f
16listview 和 recycleview 与子控件点击冲突
android:descendantFocusability="blocksDescendants"
属性的值有三种:
?
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
?
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
?
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
用法:这个属性直接丢给viewgroup
<ListView
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:divider="@drawable/leftxian1"
android:id="@+id/flfg_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
17.
focusable表示 移动光标时 是否能聚焦到组件上,比如按钮,就是移动光标是按钮会变成选中状态,如果focusable为false,那么就跳过此 组件,下一个组件变成选中状态。
focusableInTouchMode可以通过触摸获取焦点
Android:focusable="true"
android:focusableInTouchMode="true"
18.Fragment切换Fragent走的生命周期方法:
开始 onAttach()-onCreate-onstart() -onResume()
跳转:onPause-onStop- 回来: onstart() onResume()
18.Android5.0以下drawable tag vector错误的解决办法
https://www.cnblogs.com/chunmei123/p/10130476.html
1.xml:控件改为ImageView,android:src改为app:srcCompat
2.在Activity开头加上:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
19.Android 程序打包为APK
https://www.cnblogs.com/chy18883701161/p/10864887.html
20.gSON的Json转化
Gson gson = new Gson();
UserModule mUserModule=gson.fromJson(result, UserModule.class);
Gson gson = new Gson();
String userStr = gson.toJson(user);
20Json转化fastjson
String jsonstr=JSON.toJSONString(UserModule.class);
UserModule mUserModule=JSONObject.parseObject("",UserModule.class);
21.工作
工具、
适配(不同的控件,页面,布局方式)
重构
内存优化
功能预言
架构设计
22.Android进阶之路 - 通过WebView与H5前端进行完美交互
https://blog.csdn.net/qq_20451879/article/details/79136579
23.Webview的奇技淫巧-总结篇
https://blog.csdn.net/u011200604/article/details/82182764
24、
android webview onJsAlert只调用一次的问题,并且页面卡死的问题
需要在每次调完后设置参数JsResult调用cancel()或者confirm()方法,这样子:
class?MyWebChromeClient?extends?WebChromeClient?{???
????????
@Override???
???????
?public?boolean?onJsAlert(WebView?view,?String?url,?String?message,?JsResult?result)?{???
????????????
Toast.makeText(DetailActivity.this,?message,?Toast.LENGTH_SHORT).show();???
???????????
?result.cancel();???
????????????
return?true;???
???????
?}???
????} ?
25.Json拼装
将一个javabean转化为一个json字符串,再拼装上一个jsonObject
一般jsonObject用ORG.JSON中的jsonObject(jsonstring)拼装
但是要是拼装的是JsonArray,拼装完后jsonAray位置容易用引号引起来,导致报错,所以不要用拼装的,要重新定义一个类
26.
BaseQuickAdapter——RecyclerView通用适配器使用
https://www.jianshu.com/p/40457c16e44a
27.返回按钮设计
<ImageView
android:id="@+id/returnview"
android:layout_width="?android:actionBarSize"
android:layout_height="?android:actionBarSize"
app:srcCompat="@drawable/ic_return"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingRight="20dp"
android:layout_marginBottom="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"></ImageView>
28.将蜂鸟云地图导入Fragment展示
坑:
标注起点图层崩溃
是由于标注起点不能用mStartImageLayer = new FMImageLayer(mMap, mStartGroupId);
,用
imageLayer = mMap.getFMLayerProxy().createFMImageLayer(fmGeoCoord.getGroupId());
mMap.addLayer(imageLayer);
29.性能优化:
利用 Android Profiler 测量应用性能
https://developer.android.google.cn/studio/profile/android-profiler
30。用户手势检测-GestureDetector使用详解
https://www.cnblogs.com/ldq2016/p/7000300.html
31.仿新版微信的小程序下拉栏
http://www.sohu.com/a/215282365_611601
32.TAG,设置TAG = this.getClass().getSimpleName();
33.LitePager(仿网易云音乐-歌单广场效果)
https://www.wanandroid.com/blog/show/2573
34.Flutter 小说阅读 App
https://www.wanandroid.com/blog/show/2634
35.如何使用git把本地代码上传(更新)到github上
https://baijiahao.baidu.com/s?id=1619544681032320225&wfr=spider&for=pc
36.
如何在github上传本地项目代码(新手使用)
https://blog.csdn.net/xqhys/article/details/98113227
github上传代码详细过程
https://www.jianshu.com/p/de2d99752924
1.下载安装git
2.在要上传的文件下右击选择git bash,打开终端
3.将github上的地址复制下来,创建地址的时候必须选择readme文件的创建
调用git clone 复制下来的地址
4.这样就会在本地文件下出现一个github上建的文件夹,cd 到该文件夹下
5.必须将要上传的资料全部拷贝到这个文件夹下
6.然后git add .加进去仓库里面去
7.然后git commit -m "描述"提交
8.上传至github,git push origin master(如果push出错,就先pull一下,git pull origin master再push)
git本地代码管理
https://www.cnblogs.com/yanqingyang/p/9833884.html

浙公网安备 33010602011771号