android menuitem 动画,Android NavigationView MenuItem图标动画

我试图理解菜单图标动画是否应该在新的中运行

导航视图,与动作项动画相同的方式或任何其他视图,用于任何应用布局.

下面的代码对我不起作用.

我用它来测试Android发布的代码示例以获得新的支持

图书馆.

相同的动画代码在工具栏上很好地工作.还尝试了较旧的API

动画(紧接着链接:Animated Icon for ActionItem)

我想我错过了一些东西……

谢谢你.

码:

XML:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/drawer_layout"

android:layout_height="match_parent"

android:layout_width="match_parent"

android:fitsSystemWindows="true"

android:background="@color/lightPrimaryColor">

android:id="@+id/nav_view"

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:layout_gravity="start"

android:fitsSystemWindows="true"

android:background="@color/lightPrimaryColor"

app:headerLayout="@layout/nav_header"

app:theme="@style/menu_item_style"

app:menu="@menu/drawer_view"/>

drawer_view:

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:class="http://schemas.android.com/tools"

class:actionViewClass="android.widget.ProgressBar">

android:id="@+id/drawer_menu">

android:id="@+id/nav_examp_lists"

android:icon="@drawable/refresh1"

android:title="@string/example"

app:showAsAction="always"

android:layoutDirection="rtl"/>

android:id="@+id/nav_split_lists"

android:title="@string/split"

android:icon="@drawable/refresh2"

app:showAsAction="always"

app:actionViewClass="android.widget.ImageView"/>

android:id="@+id/nav_change_net"

android:title="@string/change"

android:icon="@drawable/refresh3"

app:showAsAction="always"

android:layoutDirection="rtl"/>

Java的:

navigationView.setNavigationItemSelectedListener(

new NavigationView.OnNavigationItemSelectedListener() {

@Override

public boolean onNavigationItemSelected(MenuItem menuItem) {

menuItem.setChecked(true);

mDrawerLayout.closeDrawers();

switch (menuItem.getItemId()) {

case R.id.nav_my_lists:

anim = AnimatorInflater.loadAnimator(getApplication(), R.animator.rotation);

anim.setTarget(menuItem.getIcon());

anim.setDuration(2000);

//anim.setStartDelay(10);

anim.addListener(new AnimatorListenerAdapter() {

@Override

public void onAnimationStart(Animator animation) {

Toast.makeText(getApplication(), "Started...", Toast.LENGTH_SHORT).show();

}

});

anim.start();

boolean run = anim.isRunning();

String title = menuItem.getTitle().toString();

loadShoppingList(title);

return true;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值