java – 如何在单击之前在ImageButton中设置有效的图像
发布时间:2020-12-15 02:16:53 所属栏目:Java 来源:网络整理
导读:我想使用所选图像来设置具有效果的按钮,然后单击它,然后单击效果在 ImageView中应用相同的图像,但是它的方式使用默认图像,而不是选择的图像. imgView = (ImageView) findViewById(R.id.imgView); btnSepia = (ImageButton) findViewById(R.id.btnSepia); Bit
|
我想使用所选图像来设置具有效果的按钮,然后单击它,然后单击效果在
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);
}
});
谢谢(); 抱歉,我的英语不是我的母语. 解决方法
我无法得到你的问题,关于我可以通过上面的描述得到什么,是你想要在行动上改变图像.
所以你可以使用Selector,基本上不要直接放置你的图像源而是在图像源中使用选择器. 要创建选择器,请在资源中定义selector.xml,使用以下方式: <selector>
<item
android:state="<Give_State_HERE>"
android:drawable="<GIVE_Source_of_Your_Drawable_Here"/>
</selector>
试试这个并指定这个xml作为你的img:source.希望这会有所帮助 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
