我有一个imageview,我已经设置了一个从网址获取的位图.在imageview上,我设置了一个打开对话框的onClickListener.
当按下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) 我正在使用Lollipop设备(MotoG 2014),我读到了进度条着色,但这不起作用......我得到了默认的进度条颜色.我在这里错过了什么?
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="50dp"
android:layout_height="50dp"
android:backgroundTintMode="src_in"
android:indeterminate="true"
android:indeterminateTint="#f00" />
Run Code Online (Sandbox Code Playgroud)
非常感谢.
android android-layout android-theme material-design android-5.0-lollipop
我目前正在开发的应用程序使用了很多ImageViews作为按钮.这些按钮上的图形使用Alpha通道淡出按钮的边缘,使它们看起来不规则.目前,我们必须为每个按钮生成2个图形(1个用于选定/聚焦/按下状态,另一个用于默认的未选择状态),并使用XML文件中为每个按钮定义的StateListDrawable.
虽然这很好用但看起来非常浪费,因为所有选定的图形都只是未选定按钮的着色版本.这些花费时间来制作(无论多少)并占用最终APK中的空间.似乎应该有一个简单的方法来自动.
看起来,完美的解决方案是为每个按钮使用ImageViews,并在其tint属性中指定ColorStateList.这种方法的优点是,所有按钮(共享相同色调)只需要一个XML ColorStateList.但它不起作用.如前所述这里,ImageView的抛出NumberFormatException异常时提供给色调值以外的任何其他单一颜色.
我的下一次尝试是为选定的drawable使用LayerDrawable.在图层列表中,我们将原始图像放在堆栈底部,由半透明矩形覆盖.这适用于按钮图形的实体部分.然而,应该是完全透明的边缘现在与顶层的颜色相同.
有没有人遇到过这个问题,找到了合理的解决方案?我想坚持使用XML方法,但可能会编写一个简单的ImageView子类,它将在代码中进行所需的着色.
如何更改发送图标的默认颜色ImageButton?
<ImageButton
android:id="@+id/ImageButton1"
android:layout_width="0dp"
android:paddingTop="5dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:gravity="right"
android:scaleType="center"
android:src="@android:drawable/ic_menu_send" />
Run Code Online (Sandbox Code Playgroud)
我想用灰色代替当前的白色.