gpt4 book ai didi

java - 如何在单击之前在ImageButton中设置具有效果的图像

转载 作者:太空宇宙 更新时间:2023-11-03 11:02:20 25 4
gpt4 key购买 nike

我想用选中的图片给按钮设置效果,点击之前,再点击效果在ImageView中应用相同的图片,但是这样,使用默认图片,而不是选择的图像。

    imgView = (ImageView) findViewById(R.id.imgView);
btnSepia = (ImageButton) findViewById(R.id.btnSepia);

BitmapDrawable abmp = (BitmapDrawable) imgView.getDrawable();
bmp = abmp.getBitmap();

mProgress = (ProgressBar) findViewById(R.id.progressBar);
mProgress.setVisibility(View.INVISIBLE);

Intent i = new Intent(
Intent.ACTION_GET_CONTENT,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/");

startActivityForResult(i, RESULT_LOAD_IMAGE);


final Drawable resSepia = new BitmapDrawable(getResources(), bmp);
imgView.setImageDrawable(resSepia);

Handler handler = new Handler();

final Runnable r = new Runnable() {
@Override
public void run() {
if (resSepia == null)
return;
final ColorMatrix matrixA = new ColorMatrix();
// making image B&W
matrixA.setSaturation(0);

final ColorMatrix matrixB = new ColorMatrix();
// applying scales for RGB color values
matrixB.setScale(1f, .95f, .82f, 1.0f);
matrixA.setConcat(matrixB, matrixA);

final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrixA);
resSepia.setColorFilter(filter);

btnSepia.setImageDrawable(resSepia);
}
};
handler.postDelayed(r, 1000);

btnSepia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

imgView.setImageDrawable(resSepia);

}
});

谢谢();

抱歉,我的英语不是我的母语。

最佳答案

我无法理解你的问题,关于我通过上面的描述可以理解的是,你想在操作时更改图像。

所以你可以使用选择器,基本上不要直接放置图像源,而是在图像源中使用选择器。

要制作一个选择器,在resources中定义一个selector.xml,使用方式: <selector> (在xml中指定选择器标签)并在其下定义一个项目标签,该标签将具有以下属性

<selector>
<item
android:state="<Give_State_HERE>"
android:drawable="<GIVE_Source_of_Your_Drawable_Here"/>
</selector>

试试这个并将这个 xml 指定为您的 img:source。希望这对您有帮助

关于java - 如何在单击之前在ImageButton中设置具有效果的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39714598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com