相关疑难解决方法(0)

如何在焦点/按下时更改ImageButton的色调

我有一个ImageButton在我的应用程序,我需要在按钮时更改图像的色调pressed/focused.我有一个从XML文件ImageButton获取它的集合,src如下所示:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- pressed -->
    <item 
        android:state_pressed="true"
        android:tint="@color/black"
        android:drawable="@drawable/search"
        />

    <!-- focused -->
    <item 
        android:state_focused="true"
        android:tint="@color/black"
        android:drawable="@drawable/search"
        />

    <!-- default -->
    <item
        android:tint="@null"
        android:drawable="@drawable/search"
        />

</selector>
Run Code Online (Sandbox Code Playgroud)

但是,ImageButton按下或聚焦时不会应用色调- 图像只显示正常.黑色一直定义为黑色#000000.有任何想法吗?

android image tint selector imagebutton

57
推荐指数
4
解决办法
9万
查看次数

XML中的setColorFilter()是否等效?

我想知道是否ColorFilter可以在XML的XML中设置,View或者是否唯一的方法是setColorFilter()在Java中使用.

java xml android

38
推荐指数
4
解决办法
1万
查看次数

如何使用选择器在android中着色imageview

我想使用xml为我的tabhost图标着色,而不是以编程方式进行(我无论如何都无法做到这一点)...所以我在SO上找到了这个帖子:Android imageview更改色调来模拟按钮点击

这似乎是一个非常好的解决方案,但我无法在我的项目中正确调整它......我做了以下更改:

public class TintableImageView extends ImageView {
private ColorStateList tint;

public TintableImageView(Context context) {
    super(context);
}

//this is the constructor that causes the exception
public TintableImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs, 0);
}

public TintableImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context, attrs, defStyle);
}

//here, obtainStyledAttributes was asking for an array
private void init(Context context, AttributeSet attrs, int defStyle) {
    TypedArray a = context.obtainStyledAttributes(attrs, new int[]{R.styleable.TintableImageView_tint}, defStyle, 0);
    tint = …
Run Code Online (Sandbox Code Playgroud)

android android-imageview android-selector

30
推荐指数
5
解决办法
6万
查看次数

在galaxy选项卡上启动时,xml Android颜色文件上的int无效

当我尝试在带有android 4.1.2的Galaxy Tab上启动它时,我的Android应用程序崩溃了.错误是:

09-26 21:06:10.293: E/AndroidRuntime(9596): Caused by: java.lang.NumberFormatException: Invalid int: "res/color/tw_primary_text_holo_dark.xml"
Run Code Online (Sandbox Code Playgroud)

此错误不会出现在Android 4.2.2的galaxy s4上,也不会出现在Android 4.1.1的模拟器(手机或标签屏幕大小)上.

我试图找到这个tw_primary_text_holo_dark.xml文件,我找不到它.但是在primary_text_holo_dark中显然存在.

你知道为什么这只出现在我的标签上吗?

android

8
推荐指数
2
解决办法
2389
查看次数