是否有可能为api <21进行可绘制的着色工作?
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_calendar"
android:tint="@color/primary" />
Run Code Online (Sandbox Code Playgroud)
工作正常但仅适用于具有API21的设备.针对较低api设备或AppCompat支持的任何解决方法?找不到任何东西.
Sak*_*boy 103
使用AppCompatImageView如下:
<android.support.v7.widget.AppCompatImageView
android:id="@+id/my_appcompat_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"
android:tint="#636363"
/>
Run Code Online (Sandbox Code Playgroud)
确保您拥有最新appcompat-v7的应用程序build.gradle.
示例:compile 'com.android.support:appcompat-v7:25.0.0'在您的应用中build.gradle.
Sim*_*ges 42
您可以使用源代码实现这一目标.之前的着色不受支持DrawableCompat.从支持库22.1开始,您可以这样做,但您需要以这种方式执行此操作:
Drawable normalDrawable = getResources().getDrawable(R.drawable.drawable_to_tint);
Drawable wrapDrawable = DrawableCompat.wrap(normalDrawable);
DrawableCompat.setTint(wrapDrawable, getResources().getColor(R.color.colorPrimaryLight));
Run Code Online (Sandbox Code Playgroud)
Jon*_*nik 22
难道你不能简单地使用ImageView来显示你的Drawable吗?android:tint适用于较旧的API级别.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_calendar"
android:tint="@color/primary"
/>
Run Code Online (Sandbox Code Playgroud)
Jar*_*ows 17
此前有人问过类似的问题:https://stackoverflow.com/a/26533340/950427
Android Drawable Tinting仅在Android 5.0+(API 21+)中受支持.(确实说" At the moment this is limited to coloring the action bar and some widgets.").
主题化
...
设置这些属性时,AppCompat会自动将其值传播到API 21+上的框架属性.这会自动为状态栏和概述(最近)任务条目着色.
在较旧的平台上,AppCompat尽可能模拟颜色主题.目前,这仅限于为操作栏和一些小部件着色.
和
小工具着色
在使用Android 5.0的设备上运行时,所有小部件都使用我们刚才谈到的颜色主题属性进行着色.在Lollipop上有两个主要功能:drawable着色,并在drawables中引用主题属性(形式为?attr/foo).
AppCompat在早期版本的Android上为UI小部件的子集提供了类似的行为:
AppCompat的工具栏(动作模式等)提供的一切EditText Spinner CheckBox RadioButton Switch(使用新的android.support.v7.widget.SwitchCompat)CheckedTextView你不需要做任何特别的事情来使这些工作,只需使用这些控件像往常一样你的布局和AppCompat将完成其余的工作(有一些注意事项;请参阅下面的常见问题解答).
资料来源:
http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
https://chris.banes.me/2014/10/17/appcompat-v21/
Ank*_*ngh 13
现在AppCompatImageView,AppCompatButton将取代ImageView,Button以支持具有较低API的设备上的色调.检查链接以获取更多详细信息 AppCompatImageView,AppCompatButton
对于您可以使用的着色图像imageView.setColorFilter(int color).这适用于API 8,用于将我的黑色图像着色为我想要的颜色.这可以取代,setImageTintList()但只是使用android:tint也应该工作.
使用这个命名空间
xmlns:app="http://schemas.android.com/apk/res-auto"
然后你可以用 app:tint 替换每个 android:tint。这为我解决了问题。
| 归档时间: |
|
| 查看次数: |
69734 次 |
| 最近记录: |