大佬教程收集整理的这篇文章主要介绍了android – 展开动作视图时的导航抽屉图标(汉堡包和箭头)动画,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当导航抽屉图标从汉堡包转换为箭头或反之时,我确保会有动画.
我使用以下技术https://stackoverflow.com/a/26469738/72437
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> </style> <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> <item name="spinBars">true</item> <item name="color">@android:color/white</item> </style> </resources>
当我按下导航抽屉,滑入&滑出菜单.但是,它不是很有用.根据材料设计指南,导航抽屉片段应为全高.因此,当它开始滑出时,它将阻止导航抽屉图标.
在处理我的搜索按钮(action_search)时,我更感兴趣的是执行动画,该按钮充当我的工具栏的动作视图.
@H_959_5@main_menu.xml
<item android:id="@+id/action_search" android@R_764_6964@="Search me" android:icon="@drawable/ic_add_white_24dp" app:showAsAction="always|collapseActionView" app:actionLayout="@layout/collapsible_searchtext" /> <item android:id="@+id/action_setTings" android@R_764_6964@="@String/action_setTings" android:orderInCategory="100" app:showAsAction="never" />
collapsible_searchtext.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://scheR_373_11845@as.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <android.widget.AutoCompleteTextView android:id="@+id/search" android:dropDownWidth="match_parent" android:completionThreshold="1" android:inputType="textNoSuggestions" android:imeOptions="actionSearch|flagNoExtractUi" android:focusable="true" android:focusableInTouchMode="true" android:singleLine="true" android:hint="Search stock" android:layout_gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" /> </RelativeLayout>
>当我按下action_search时,搜索图标将扩展为AutoCompleteTextView.同时,汉堡图标将动画显示箭头图标
>当我按箭头图标时,箭头图标将动画回汉堡包图标.
我尝试通过在阅读https://stackoverflow.com/a/26480439/72437之后使用以下代码来实现目标1
private void animateHamburgerToArrow() { ValueAnimator anim = ValueAnimator.ofFloat(0f,1f); anim.addupdateListener(new ValueAnimator.AnimatorupdateListener() { @Override public void onAnimationupdate(ValueAnimator valueAnimator) { float slideOffset = (Float) valueAnimator.getAnimatedValue(); actionBarDrawerToggle.onDrawerSlide(drawerLayout,slideOffset); } }); anim.seTinterpolator(new DecelerateInterpolator()); // You can change this duration to more closely match that of the default animation. anim.setDuration(500); anim.start(); } @Override public Boolean onOptionsItemSELEcted(MenuItem item) { if (actionBarDrawerToggle.onOptionsItemSELEcted(item)) { return true; } // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button,so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_setTings) { animateHamburgerToArrow(); return true; } else if (id == R.id.action_search) { animateHamburgerToArrow(); return true; } return super.onOptionsItemSELEcted(item); }
当我按下action_search时,汉堡包图标会变为箭头图标.但是,没有动画.我可以知道有什么我错过了吗?
更新
我怀疑导航抽屉使用的左箭头与搜索操作视图使用的左箭头不同.它们是两个不同的实例.
这是因为如果我点击action_setTings,我可以观察动画.但是,如果我单击action_search,我将不会观察动画.我怀疑搜索操作视图使用了左箭头,“阻止”导航抽屉的图标(包括汉堡包和箭头)
以上是大佬教程为你收集整理的android – 展开动作视图时的导航抽屉图标(汉堡包和箭头)动画全部内容,希望文章能够帮你解决android – 展开动作视图时的导航抽屉图标(汉堡包和箭头)动画所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。