在我的应用程序中,我必须为通知设置一个大图标.LargeIcon必须是一个Bitmap,我的drawables是矢量图像(Android中的新功能,请看这个链接)问题是当我尝试解码一个矢量图像的资源时,我得到一个null返回.
以下是代码示例:
if (BitmapFactory.decodeResource(arg0.getResources(), R.drawable.vector_menu_objectifs) == null)
Log.d("ISNULL", "NULL");
else
Log.d("ISNULL", "NOT NULL");
Run Code Online (Sandbox Code Playgroud)
在这个例子中,当我用一个"普通"图像替换R.drawable.vector_menu_objectifs,例如一个png例如,结果不为空(我得到正确的位图)是否有我缺少的东西?
我有两张想要褪色的图像.最初他们都使用imageview.然后我使用.getDrawable()来获取图像的drawable.
这是我使用的代码
Drawable backgrounds[] = new Drawable[2];
backgrounds[0] = BackgroundImage.getDrawable();
backgrounds[1] = BackgroundImageBlurred.getDrawable();
TransitionDrawable crossfader = new TransitionDrawable(backgrounds);
crossfader.startTransition(3000);
Run Code Online (Sandbox Code Playgroud)
它只显示第一个数组元素上的图像,无论如何它都显示,因为两个图像都设置为在XML中可见.
转型没有开始
任何帮助,将不胜感激 :)
我想在Android中创建一个带有文本和背景图像的Button.背景图像应每X次交叉淡入淡出.
我使用带有2个图像的TransitionDrawable工作.
但我无法使用2个以上的图像.
是)我有的 :
在Java代码中,我创建一个Button并设置一个背景(这是一个在XML中定义的TransitionDrawable).我开始过渡.
final Button b = new Button(getApplicationContext());
b.setTextColor(getResources().getColor(R.color.white));
b.setText("Some text");
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.tile));
StateListDrawable background = (StateListDrawable) b.getBackground();
TransitionDrawable td = (TransitionDrawable) background.getCurrent();
td.startTransition(2000);
Run Code Online (Sandbox Code Playgroud)
在XML中我在tile.xml中定义
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#449def" />
</shape>
</item>
<item android:drawable="@drawable/transition">
<shape>
<solid
android:color="#0000ff" />
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
最后是一个transition.xml
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/desert"/>
<item android:drawable="@drawable/hydrangeas" />
<item android:drawable="@drawable/jellyfish" />
</transition>
Run Code Online (Sandbox Code Playgroud)
现在效果是,当我启动应用程序时,会显示沙漠图像.这个图像交叉渐变到绣球花图像应该.但水母图像从未显示过.
在TransitionDrawables的文档中,声明您可以指定2个以上的drawable,但我无法使其工作.
我也试过这个没有任何XML,但在纯JAVA,但这给出了完全相同的问题:-(