Android Button的基本用法详解
Button的Click点击事件处理:
mButtonBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Log.e("================", "MenuBackBtnListen"); MenuimageView.setVisibility(View.INVISIBLE); mButtonBack.setVisibility(View.INVISIBLE); buttonCmdLl.setVisibility(View.INVISIBLE); mLabel.setVisibility(View.INVISIBLE); } });
Button的Press状态的获取及调用:
mButtonBack.setOnTouchListener(new View.OnTouchListener() { InputStream is = null; @Override public boolean onTouch(View arg0, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN){ try { is = asm.open("ReturnBtnPress.png"); } catch (IOException e) { e.printStackTrace(); } }else if(event.getAction() == MotionEvent.ACTION_UP){ try { is = asm.open("ReturnBtnNormal.png"); } catch (IOException e) { e.printStackTrace(); } } mButtonBack.setBackground(Drawable.createFromStream(is, null)); return false; } });
说明:
private AssetManager asm;asm=getAssets();
图片资源是放在 /Android/assets/ 文件夹下。
没有用R资源引用图片。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
新闻热点
疑难解答