美文网首页
android 知识

android 知识

作者: ambe_gzy | 来源:发表于2019-08-26 16:10 被阅读0次

    c方便自己查找用过的资料


    AppCompatTextView自动适应文字大小:

    app:autoSizeTextType="uniform"//允许自动调整字体大小

    app:autoSizeStepGranularity="2dp"//调节间隔

    app:autoSizeMaxTextSize="14sp"//最大值

    app:autoSizeMinTextSize="10dp"//最小值


    渐变颜色:

    <gradient android:angle="315" android:endColor="@color/colorPrimaryApp" android:startColor="@color/colorPrimaryApp" />


    边框

    <stroke android:color="@color/colorPrimary" android:width="0.5dp"/>


    启动intent

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


    获取activity的context

    activity.this

    获取fragment的context

    getcontext();


    黑色通知栏

    AppUIUtils.setStatusBarTranslucent(getWindow(), true);

    AppUIUtils.setStatusBarStyle(getWindow(), true);


    navigationbar 设置小红点

    ShapeBadgeItem badgeItem1 =new ShapeBadgeItem();

    badgeItem1.setShape(ShapeBadgeItem.SHAPE_OVAL).setShapeColor(getResources().getColor(R.color.red_point_ff3636)).

    setSizeInDp(getApplicationContext(),8,8);


    tablayout自定义样式

    mTabLayout.getTabAt(0).setCustomView(view);


    读取r文件的bitmap

    Bitmap bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.test);


    弹窗有fragmentdialog appcompatdialog     fragmentdialog有时候有些问题。


    不同颜色字体:

    setText(Html.fromHtml(mContext.getResources().getString(R.string.xxx, String.valueOf(value))));

    Integer默认值为null,不是0


    imageview 图片填满图片框 android:scaleType="centerCrop"


    style相关知识 

    dialog

    <item name="android:windowBackground">@color/transparent</item>背景设置为透明

    <item name="colorAccent">@color/colorAccent</item>图标、按钮、文字的颜色

    <item name="android:ellipsize">end</item>尾部自动隐藏溢出数据

    <item name="android:textColorHint">@color/gray</item>提示文字颜色


    android 如何启动默认浏览器

    csdn网站教程:https://blog.csdn.net/hudashi/article/details/8176298


    修复android pie(android 9)不支持http协议问题

    在AndroidManifest.xml文件中的application节点中,配置:android:usesCleartextTraffic=“true”


    java.lang.IllegalStateException Fragment LeftFragment not attached to a context.

    使用getResource()时获取上下文出错,要进行非空判断getContext!=null.


    内边框

    <stroke android:color="@color/colorAccent" android:width="3dp"/>

    圆角

    <corners android:radius="6dp"/>

    填充颜色

    <solid android:color="@color/white"/>


    修改button默认背景颜色

    <style name="AppMainTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="buttonStyle">@style/Widget.AppCompat.Button

        <item name="colorButtonNormal">@color/colorAccent

    </style>


    修改textview点击效果

    ripple

    或者

    android:foreground="?android:attr/selectableItemBackgroundBorderless"


    textview文字居中

    android:textAlignment="center"


    自定义alertdialog问题

    setContentView(View.inflate(getContext(),R.layout.dialog_video_rename,null));布局正常

    setContentView(R.layout.dialog_video_rename)工作不正常


    添加fragment放在trycatch中进行,因此如果在activity想对fragment操作,需要在trycatch中进行,trycatch是放在子线程中进行的。

    单纯判断fragment是否为空无任何意义。


    LockSupport加锁、解锁,线程同步用到。


    android 添加依赖库,需要在build.gradle添加api project(':库名')


    FragmentTransaction

    通过FragmentTransaction实现在Activity运行时可动态地加入、移除、交换Fragment

    FragmentTransaction的主要方法介绍

    针对在一个Activity中的某个Layout中切换Fragment,无非两种方法:

    使用replace方法创建新实例,销毁旧的,无法复用

    使用hide和show方法,最终是让Fragment的View setVisibility(true还是false),不会调用生命周期,可复用。会调用onHiddenChanged。

    add(id, fragment)

    增加framgent到队列中,并显示该fragment到指定布局中。

    生命周期调用

    当fragment与activity连接并被建立时(onAttach()、onCreate()被调用过) 例如当fragment在回退栈时。

    onCreateView()、onActivityCreated()、onStart()、onResume()。

    当fragment与activity未连接并未被建立时(onAttach()、onCreate()未被调用过)

    onAttach()、onCreate()、onCreateView()、onActivityCreated()、onStart()、onResume()。

    id是告知FragmentManager,Fragment应该出现在哪个layout上

    remove(fragment)

    销毁队列中指定的fragment。

    生命周期调用:onPause()、onStop()、onDestroyView()、onDestroy()、onDetach()

    replace(id, fragment)

    先检查队列中是否已经存在,不存在就会进入队列并把其他fragment清出队列,最后显示该fragment到指定布局中。

    生命周期调用:相当于新的Fragment调用了add,队列中其他fragment调用了remove

    (新的Fragment创建:onAttach()、onCreate()、onCreateView()、onActivityCreated()、onStart()、onResume(),队列中其他fragment销毁:onPause()、onStop()、onDestroyView()、onDestroy()、onDetach())

    show(fragment)

    显示队列中的指定framgent。

    当队列中存在该fragment时并被调用过hide(fragment)时,回调onHiddenChange(boolean)。

    hide(fragment)

    隐藏队列中指定的fragment

    当队列中存在该fragment时,回调onHiddenChange(boolen)

    detach()

    会将view从UI中移除,和remove()不同,此时fragment的状态依然由FragmentManager维护。

    生命周期调用:onPause()、onStop()、onDestroyView()

    attach()

    重建view视图,附加到UI上并显示。

    生命周期调用:onCreateView()、onActivityCreated()、onStart()、onResume()

    addToBackStack()

    当移除或替换一个片段并向返回栈添加事务时,系统会停止(而非销毁)移除的片段。 如果用户执行回退操作进行片段恢复,该片段将重新启动。

    如果是替换一个片段,这个替换片段相当于add()

    移除或替换一个片段并向返回栈添加事务时,被移除片段将被detach()

    执行回退操作进行片段恢复,这个片段将被attach(),而上一个片段有两种情况

    1、如果是回退栈中还有这个片段那么将被detach()。

    2、如果回退栈没有这个片段将被remove()

    具体实例可参看:Fragment的addToBackStack()使用

    commit()

    提交本次事务,可在非主线程中被调用。主要用于多线程处理情况。在onSaveInstanceState之后提交会出现IllegalStateException,可以使用commitAllowingStateLoss代替

    commitAllowingStateLoss()

    可能会丢掉FragmentManager的状态, 即onSaveInstanceState之后任何被添加或被移除的Fragments.

    commitNow()

    提交本次事务,只在主线程中被调用。 这时候addToBackStack(string)不可用。

    参考文献https://www.jianshu.com/p/d2189b0191ef


    并发队列

    LinkBlockingQueue


    隐藏通知栏

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) //隐藏状态栏

    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) //显示状态栏


    ImageView 图片适应imageView宽高

    android:scaleType="centerCrop"


    数组与列表互相转化

    List<Integer> res = Arrays.asList(param);

    String[] mVals =tagList.toArray(new String[0]);


    android 源码阅读:

    http://androidxref.com/

    系统软件大部分在xref: /packages/apps目录下

    Definition:定义,查变量在此处查

    filepath:地址,查类名在此处查


    recycleView的 holder会复用,因此如果不对holder进行操作的话,它会将上一个位置的item的数据拿过来,因此会发生图片乱位之类的问题。


    ScrollView -LinearLayout-RelativeLayout-RecyclerView,这样布局的话只会滚动ScrollView,不会滚动RecyclerView

    相关文章

      网友评论

          本文标题:android 知识

          本文链接:https://www.haomeiwen.com/subject/fdkdectx.html