【问题标题】:Transition Drawable for actionbar in AndroidAndroid中操作栏的Transition Drawable
【发布时间】:2015-04-29 13:40:58
【问题描述】:

是否可以在 Actionbar 中使用可绘制的过渡以及如何使用? 我应该使用像这样的 xml:

 <xml version="1.0" encoding="utf-8"/>
 <transition xmlns:android="http://schemas.android.com/apk/res/android"/>
 <item android:drawable="@drawable/first_image"/>
 <item android:drawable="@drawable/second_image"/>
 </transition>

但我如何从这里继续?

【问题讨论】:

    标签: android transitiondrawable


    【解决方案1】:

    是的,这是可能的。 您可以在没有 XML 的情况下执行此操作,只需在您的代码中创建一个 TransitionDrawable

    Drawable firstImage = getDrawable(R.drawable.first_image);
    Drawable secondImage = getDrawable(R.drawable.secondImage);
    TransitionDrawable transition = new TransitionDrawable(new Drawable[] {
            firstImage, secondImage});
    

    之后将此过渡设置为 ActionBar 的背景:

    getSupportActionBar().setBackgroundDrawable(transition);
    

    然后开始过渡:

    transition.startTransition(1000);
    

    您还可以将此过渡设置为工具栏的背景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 2021-02-26
      • 2013-03-11
      • 1970-01-01
      相关资源
      最近更新 更多