跳至主要内容

博文

[Skill]慎用onBackPressed()

慎用onBackPressed() Android中在按下back键时会调用到onBackPressed()方法,onBackPressed相对于finish方法,还做了一些其他操作,而这些操作涉及到Activity的状态,所以调用还是需要谨慎对待。 问题描述 最近公司的项目在Bug统计当中,发现了一大堆IllegalStateException的报错: java.lang . IllegalStateException : Can not perform this action after onSaveInstanceState at android.support.v4.app . FragmentManagerImpl . checkStateLoss( Unknown Source ) at android.support.v4.app . FragmentManagerImpl . popBackStackImmediate( Unknown Source ) at android.support.v4.app . FragmentActivity . onBackPressed( Unknown Source ) at android.view . View . performClick( View . java : 4768 ) at android.view . View $ PerformClick . run( View . java : 19692 ) at android.os . Handler . handleCallback( Handler . java : 739 ) at android.os . Handler . dispatchMessage( Handler . java : 95 ) at android.os . Looper . loop( Looper . java : 135 ) at android.app . ActivityThread . main( ActivityThread . java : 5539 ) at java.lang.reflect . Method . invoke( Nat...

[Widget]SelectionView-快速跳选View

SelectionView ICON 快速跳选View,与列表视图搭配使用(ListView、RecyclerView),常用于联系人列表快速选取。 预览 screenshots 要求 minSdkVersion 4 链接 Github Bintray 使用 基本布局 < am .widget.selectionview.SelectionView xmlns : app = " http://schemas.android.com/apk/res-auto " android : id = " @+id/selection_sv_selection " android : layout_width = " match_parent " android : layout_height = " match_parent " app : svBarBackground = " @drawable/bg_selection_bar " app : svBarItemHeight = " 32dp " app : svBarSlider = " @drawable/ic_selection_slider " app : svBarStyle = " List " app : svBarWidth = " 32dp " app : svNoticeAnimation = " true " app : svNoticeBackground = " @drawable/bg_selection_notice " app : svNoticeHeight = " 64dp " app : svNoticeLocation = " ViewCenter " app : svNoticePadding = " 1...

[Widget]MultiActionTextView-文字可点击TextView

MultiActionTextView ICON 文字可点击TextView,设置文字部分可点击,点击执行不同操作。 预览 screenshots 要求 无 链接 Github Bintray 使用 基本布局 < am .widget.multiactiontextview.MultiActionTextView android : layout_width = " match_parent " android : layout_height = " wrap_content " /> 基本代码 MultiActionTextView textView = ( MultiActionTextView ) findViewById(id); MultiActionClickableSpan action1 = new MultiActionClickableSpan ( 0 , 7 , colorPrimary, true , false , listener); MultiActionClickableSpan action2 = new MultiActionClickableSpan ( 10 , 15 , colorAccent, false , true , listener); MultiActionClickableSpan action3 = new MultiActionClickableSpan ( 134 , 140 , colorRipple, false , true , listener); textView . setText(text, action1, action2, action3); 注意 MultiActionClickableSpan可设置是否拦截View的OnClickListener响应 MultiActionClickableSpan可以设置不同的颜色

[Widget]HeaderFooterGridView-头尾GridView

HeaderFooterGridView ICON 头尾GridView,支持AUTO_FIT模式,头尾模式有两种,无反射代码。 预览 screenshots 要求 minSdkVersion 4 链接 Github Bintray 使用 基本布局 < am .widget.headerfootergridview.HeaderFooterGridView android : id = " @+id/gird_hfg_content " android : layout_width = " match_parent " android : layout_height = " match_parent " android : columnWidth = " 64dp " android : gravity = " center " android : horizontalSpacing = " 10dip " android : numColumns = " auto_fit " android : stretchMode = " columnWidth " android : verticalSpacing = " 10dip " /> 基本代码 HeaderFooterGridView hfgContent = ( HeaderFooterGridView ) findViewById(id); hfgContent . addHeaderView(headerView); hfgContent . removeHeaderView(headerView); hfgContent . addHeaderItem(headerItem); hfgContent . removeHeaderItem(headerItem); hfgContent . addHeaderItem(headerItem...

[Widget]DrawableRatingBar-图片评级

DrawableRatingBar ICON 图片评级,双图片评级控件,可设置图片间距,支持拖动进度及点击进度,可控制最大值最小值,及是否可手动。 预览 screenshots 要求 minSdkVersion 4 链接 Github Bintray 使用 基本布局 < am .widget.drawableratingbar.DrawableRatingBar xmlns : app = " http://schemas.android.com/apk/res-auto " android : layout_width = " match_parent " android : layout_height = " wrap_content " android : layout_gravity = " center " android : drawablePadding = " 3dp " android : minHeight = " 120dp " android : padding = " 10dp " android : progressDrawable = " @drawable " app : drbGravity = " center " app : drbManually = " true " app : drbMax = " 6 " app : drbMin = " 1 " app : drbOnlyItemTouchable = " true " app : drbRating = " 4 " /> 基本代码 mRating . setRatingDrawable( Drawable , Drawable ); mRating . se...

[Widget]ReplaceLayout-交替布局

ReplaceLayout ICON 交替布局,配合TabStrip使用,达到伴随ViewPager动作而进行改变的效果,继承自FrameLayout,通过设置ReplaceAdapter来完成管理子项View的变化,并通过move(int, int, float)方法和moveTo(int)方法达到变化的效果。 预览 screenshots 要求 无 链接 Github Bintray 使用 基本布局 < am .widget.replacelayout.ReplaceLayout android : layout_width = " wrap_content " android : layout_height = " wrap_content " /> 基本代码 replaceLayout = ( ReplaceLayout ) findViewById(id); replaceLayout . setAdapter(adapter); replaceLayout . moveTo(correct); replaceLayout . move(correct, next, offset); 注意 继承自FrameLayout,仅修改必要的触摸拦截,不建议通过xml方式在其内部添加View 仅有设置ReplaceAdapter并实现其中的变化方法才能实现子View变化效果 move(int, int, float)中最后一个参数为-1~1的偏移值 清楚移动方向可使用moveLeft(int, int, float)及moveRight(int, int, float)

[Widget]WrapLayout-自动换行布局

WrapLayout icon 自动换行布局,水平排列子项,并自动换行,支持不等长不等宽子项,且可以设置垂直间距与水平间距及子项对齐模式。一般用于标签及词条条目进行自动排版。 预览 screenshots 要求 minSdkVersion 4 链接 Github Bintray 使用 基本布局 < am .widget.wraplayout.WrapLayout xmlns : app = " http://schemas.android.com/apk/res-auto " android : id = " @+id/wly_lyt_warp " android : layout_width = " match_parent " android : layout_height = " wrap_content " android : layout_margin = " 10dp " android : background = " @drawable/bg_wraplayout_content " android : horizontalSpacing = " 10dp " android : padding = " 10dp " android : verticalSpacing = " 10dp " app : wlyHorizontalSpacing = " 10dp " app : wlyVerticalSpacing = " 10dp " > ⋯ </ am .widget.wraplayout.WrapLayout> 基本代码 WrapLayout lytWrap = ( WrapLayout ) findViewById( R . id . wly_lyt_warp); lytWrap . setHori...