首页 文章 精选 留言 我的

精选列表

搜索[导航菜单],共10001篇文章
优秀的个人博客,低调大师

Android底部导航栏实现(一)之BottomNavigationBar

BottomNavigationBar这个控件的使用之前已经写过,这里不再赘述,详情请参考BottomNavigationBar的使用。 下面直接上代码: 初始化及相关设置: mBottomNavigationBar=(BottomNavigationBar)view.findViewById(R.id.bottom_navigation_bar); mBottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC); mBottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED); mBottomNavigationBar.addItem(newBottomNavigationItem(R.drawable.home_fill,getString(R.string.item_home)).setInactiveIconResource(R.drawable.home).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) .addItem(newBottomNavigationItem(R.drawable.location_fill,getString(R.string.item_location)).setInactiveIconResource(R.drawable.location).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) .addItem(newBottomNavigationItem(R.drawable.like_fill,getString(R.string.item_like)).setInactiveIconResource(R.drawable.like).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) .addItem(newBottomNavigationItem(R.drawable.person_fill,getString(R.string.item_person)).setInactiveIconResource(R.drawable.person).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1)) .setFirstSelectedPosition(0) .initialise(); mBottomNavigationBar.setTabSelectedListener(this); setDefaultFragment(); Tab的切换: @Override publicvoidonTabSelected(intposition){ FragmentTransactionbeginTransaction=getFragmentManager().beginTransaction(); switch(position){ case0: if(mHomeFragment==null){ mHomeFragment=HomeFragment.newInstance(getString(R.string.item_home)); } beginTransaction.replace(R.id.sub_content,mHomeFragment); break; case1: if(mLocationFragment==null){ mLocationFragment=LocationFragment.newInstance(getString(R.string.item_location)); } beginTransaction.replace(R.id.sub_content,mLocationFragment); break; case2: if(mLikeFragment==null){ mLikeFragment=LikeFragment.newInstance(getString(R.string.item_like)); } beginTransaction.replace(R.id.sub_content,mLikeFragment); break; case3: if(mPersonFragment==null){ mPersonFragment=PersonFragment.newInstance(getString(R.string.item_person)); } beginTransaction.replace(R.id.sub_content,mPersonFragment); } beginTransaction.commit(); } 说明:这几篇文章没有过多的文字叙述,因为这些东西也不是很难,而且都是常用的,相信很多人都了如指掌了,多说亦是废话,直接上代码看的反而更清楚。 作者:K_J 来源:51CTO

优秀的个人博客,低调大师

Smenu 0.9.17 发布,终端菜单选择工具

Smenu 0.9.17 已经发布。Smenu 是一个选择过滤器,就像 sed 是编辑过滤器一样。 该工具从标准输入或文件中获取单词,并在滚动窗口中以不同的布局将它们显示在屏幕上。 部分更新内容 修复了获取光标位置的方法 解决了标题占用太多行时的显示问题 重新打开 /dev/tty 失败现在是致命的 现在仅在需要时才捕获有趣的信号 调整终端大小时的刷新机制已修复并得到改善 添加了 -Q|-ignore_quotes 选项以提供一种方法在将输入流/文件拆分为单词时忽略引号 现在会在用法错误的情况下显示用法文本线 创建包含/排除 RE 模式的代码已简化 smenu 现在模仿 Unix shell 信号处理 -!|-int |-int_string 选项已添加,在 smenu 会话中输入 ^C 时,用以定义一个字符串在标准输出上显示 详细内容请查看更新公告。

优秀的个人博客,低调大师

自制WheelView沉浸式菜单及Dialog样式Activity

自制一个简单的WheelView控件,配合Dialog样式的Activity使用 为什么不直接用Dialog呢? 因为感觉Dialog有时候传值会很麻烦,而且写起来也不方便。用Activity仿的话就很方便,效果也不错。 当然用Dialog也是可以的,具体根据项目需求和个人习惯而定。 效果图如下: 那么直接贴核心代码,源码我会在博客底部发链接 Dialog样式的Activity布局: <?xmlversion="1.0"encoding="utf-8"?> <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="80dp"> <TextView android:id="@+id/rate_tv" android:layout_width="fill_parent" android:layout_height="45dp" android:background="@drawable/more_top_nor" android:gravity="center" android:text="选项" android:drawableBottom="@drawable/cell_cut_line" android:textColor="@android:color/black" android:textSize="18sp"/> <com.lg.wheelviewdemo.PickerView android:id="@+id/pickerview" android:layout_below="@id/rate_tv" android:background="@drawable/more_content_nor" android:layout_width="match_parent" android:layout_height="150dp"/> <TextView android:onClick="onClick" android:layout_width="fill_parent" android:layout_height="45dp" android:drawableTop="@drawable/cell_cut_line" android:layout_below="@id/pickerview" android:text="确定" android:textColor="@android:color/black" android:textSize="18sp" android:gravity="center" android:background="@drawable/more_bottom_nor"/> </RelativeLayout> PickerView也就是自制的WheelView,代码如下: /** *滚动选择器 */ publicclassPickerViewextendsView{ publicstaticfinalStringTAG="PickerView"; /** *text之间间距和minTextSize之比 */ publicstaticfinalfloatMARGIN_ALPHA=2.3f; /** *自动回滚到中间的速度 */ publicstaticfinalfloatSPEED=2; privateList<String>mDataList; /** *选中的位置,这个位置是mDataList的中心位置,一直不变 */ privateintmCurrentSelected; privatePaintmPaint; privatefloatmMaxTextSize=30; privatefloatmMinTextSize=15; privatefloatmMaxTextAlpha=255; privatefloatmMinTextAlpha=100; privateintmViewHeight; privateintmViewWidth; privatefloatmLastDownY; /** *滑动的距离 */ privatefloatmMoveLen=0; privatebooleanisInit=false; privateonSelectListenermSelectListener; privateTimertimer; privateMyTimerTaskmTask; HandlerupdateHandler=newHandler(){ @Override publicvoidhandleMessage(Messagemsg){ if(Math.abs(mMoveLen)<SPEED){ mMoveLen=0; if(mTask!=null){ mTask.cancel(); mTask=null; performSelect(); } }else //这里mMoveLen/Math.abs(mMoveLen)是为了保有mMoveLen的正负号,以实现上滚或下滚 mMoveLen=mMoveLen-mMoveLen/Math.abs(mMoveLen)*SPEED; invalidate(); } }; publicPickerView(Contextcontext){ super(context); init(); } publicPickerView(Contextcontext,AttributeSetattrs){ super(context,attrs); init(); } publicvoidsetOnSelectListener(onSelectListenerlistener){ mSelectListener=listener; } privatevoidperformSelect(){ if(mSelectListener!=null) mSelectListener.onSelect(mDataList.get(mCurrentSelected)); } publicvoidsetData(List<String>datas){ mDataList=datas; mCurrentSelected=datas.size()/2; invalidate(); } /** *选择选中的item的index * *@paramselected */ publicvoidsetSelected(intselected){ mCurrentSelected=selected; intdistance=mDataList.size()/2-mCurrentSelected; if(distance<0) for(inti=0;i<-distance;i++){ moveHeadToTail(); mCurrentSelected--; } elseif(distance>0) for(inti=0;i<distance;i++){ moveTailToHead(); mCurrentSelected++; } invalidate(); } /** *选择选中的内容 * *@parammSelectItem */ publicvoidsetSelected(StringmSelectItem){ for(inti=0;i<mDataList.size();i++) if(mDataList.get(i).equals(mSelectItem)){ setSelected(i); break; } } privatevoidmoveHeadToTail(){ Stringhead=mDataList.get(0); mDataList.remove(0); mDataList.add(head); } privatevoidmoveTailToHead(){ Stringtail=mDataList.get(mDataList.size()-1); mDataList.remove(mDataList.size()-1); mDataList.add(0,tail); } @Override protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){ super.onMeasure(widthMeasureSpec,heightMeasureSpec); mViewHeight=getMeasuredHeight(); mViewWidth=getMeasuredWidth(); //按照View的高度计算字体大小 mMaxTextSize=mViewHeight/4.0f; mMinTextSize=mMaxTextSize/2f; isInit=true; invalidate(); } privatevoidinit(){ timer=newTimer(); mDataList=newArrayList<String>(); mPaint=newPaint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Style.FILL); mPaint.setTextAlign(Align.CENTER); mPaint.setColor(Color.WHITE); } @Override protectedvoidonDraw(Canvascanvas){ super.onDraw(canvas); //根据index绘制view if(isInit) drawData(canvas); } privatevoiddrawData(Canvascanvas){ //先绘制选中的text再往上往下绘制其余的text floatscale=parabola(mViewHeight/4.0f,mMoveLen); floatsize=(mMaxTextSize-mMinTextSize)*scale+mMinTextSize; mPaint.setTextSize(size); mPaint.setColor(this.getResources().getColor(android.R.color.black)); mPaint.setAlpha((int)((mMaxTextAlpha-mMinTextAlpha)*scale+mMinTextAlpha)); //text居中绘制,注意baseline的计算才能达到居中,y值是text中心坐标 floatx=(float)(mViewWidth/2.0); floaty=(float)(mViewHeight/2.0+mMoveLen); FontMetricsIntfmi=mPaint.getFontMetricsInt(); floatbaseline=(float)(y-(fmi.bottom/2.0+fmi.top/2.0)); canvas.drawText(mDataList.get(mCurrentSelected),x,baseline,mPaint); //绘制上方data for(inti=1;(mCurrentSelected-i)>=0;i++){ drawOtherText(canvas,i,-1); } //绘制下方data for(inti=1;(mCurrentSelected+i)<mDataList.size();i++){ drawOtherText(canvas,i,1); } } /** *@paramcanvas *@paramposition距离mCurrentSelected的差值 *@paramtype1表示向下绘制,-1表示向上绘制 */ privatevoiddrawOtherText(Canvascanvas,intposition,inttype){ floatd=(float)(MARGIN_ALPHA*mMinTextSize*position+type *mMoveLen); floatscale=parabola(mViewHeight/4.0f,d); floatsize=(mMaxTextSize-mMinTextSize)*scale+mMinTextSize; mPaint.setTextSize(size); mPaint.setAlpha((int)((mMaxTextAlpha-mMinTextAlpha)*scale+mMinTextAlpha)); floaty=(float)(mViewHeight/2.0+type*d); FontMetricsIntfmi=mPaint.getFontMetricsInt(); floatbaseline=(float)(y-(fmi.bottom/2.0+fmi.top/2.0)); canvas.drawText(mDataList.get(mCurrentSelected+type*position), (float)(mViewWidth/2.0),baseline,mPaint); } /** *抛物线 * *@paramzero零点坐标 *@paramx偏移量 *@returnscale */ privatefloatparabola(floatzero,floatx){ floatf=(float)(1-Math.pow(x/zero,2)); returnf<0?0:f; } @Override publicbooleanonTouchEvent(MotionEventevent){ switch(event.getActionMasked()){ caseMotionEvent.ACTION_DOWN: doDown(event); break; caseMotionEvent.ACTION_MOVE: doMove(event); break; caseMotionEvent.ACTION_UP: doUp(event); break; } returntrue; } privatevoiddoDown(MotionEventevent){ if(mTask!=null){ mTask.cancel(); mTask=null; } mLastDownY=event.getY(); } privatevoiddoMove(MotionEventevent){ mMoveLen+=(event.getY()-mLastDownY); if(mMoveLen>MARGIN_ALPHA*mMinTextSize/2){ //往下滑超过离开距离 moveTailToHead(); mMoveLen=mMoveLen-MARGIN_ALPHA*mMinTextSize; }elseif(mMoveLen<-MARGIN_ALPHA*mMinTextSize/2){ //往上滑超过离开距离 moveHeadToTail(); mMoveLen=mMoveLen+MARGIN_ALPHA*mMinTextSize; } mLastDownY=event.getY(); invalidate(); } privatevoiddoUp(MotionEventevent){ //抬起手后mCurrentSelected的位置由当前位置move到中间选中位置 if(Math.abs(mMoveLen)<0.0001){ mMoveLen=0; return; } if(mTask!=null){ mTask.cancel(); mTask=null; } mTask=newMyTimerTask(updateHandler); timer.schedule(mTask,0,10); } classMyTimerTaskextendsTimerTask{ Handlerhandler; publicMyTimerTask(Handlerhandler){ this.handler=handler; } @Override publicvoidrun(){ handler.sendMessage(handler.obtainMessage()); } } publicinterfaceonSelectListener{ voidonSelect(Stringtext); } Dialog样式Activity: privatePickerViewpickerView; privateList<String>mDatas; @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_wheel); pickerView=(PickerView)findViewById(R.id.pickerview); mDatas=newArrayList<>(); for(inti=1;i<60;i++){ mDatas.add(""+i); } pickerView.setData(mDatas); pickerView.setSelected(MainActivity.num-1); pickerView.setOnSelectListener(newPickerView.onSelectListener(){ @Override publicvoidonSelect(Stringtext){ MainActivity.num=Integer.parseInt(text); } }); } publicvoidonClick(Viewview){ MainActivity.tv.setText("当前选择"+MainActivity.num); finish(); } 接下来要给Activity换上Dialog样式 在styles.xml中加上 <stylename="MyDialogStyle"parent="Theme.AppCompat.Dialog"> <itemname="android:windowFrame">@null</item> <itemname="windowNoTitle">true</item> <!--边框--> <itemname="android:windowIsFloating">true</item> <!--是否浮现在activity之上--> <itemname="android:windowIsTranslucent">true</item> <!--半透明--> <itemname="android:windowNoTitle">true</item> <!--无标题--> <itemname="android:windowBackground">@android:color/transparent</item> <!--背景透明--> <itemname="android:backgroundDimEnabled">true</item> <!--模糊--> </style> AndroidManifest.xml中: <activityandroid:name=".WheelActivity" android:theme="@style/MyDialogStyle"/> 源码地址:http://down.51cto.com/data/2223518

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册