Code is as follows
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;
public class MainActivity extends Activity {
private ImageButton Ibtn;
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
Ibtn = (ImageButton) findViewById (R.id.imageBtn);
Ibtn.setOnTouchListener (new OnTouchListener () {
@ Override
public boolean onTouch (View v, MotionEvent event) {
if (event.getAction () == MotionEvent.ACTION_DOWN) {
Ibtn.setBackgroundDrawable (getResources (). getDrawable (R.drawable.press));
}
else if (event.getAction () == MotionEvent.ACTION_UP) {
Ibtn.setBackgroundDrawable (getResources (). getDrawable (R.drawable.nopress));
}
return false;
}
});
}
}
setBackgroundDrawable function which hit the middle of a line, can not be used, and why?
------ Solution ------------------------------------ --------
exception see detailed log ah
------ reference ------------------- --------------------
use setBackground (Drawable) instead,
for setBackground method ah
hit horizontal explanation
outdated methods, should have been gas, but for compatibility with previous versions, or take care of some of the old users, or retained.
can still be used, preferably with alternative function setBackground use
------ reference ----------------------- ----------------
or wrong, the error Call requires API level 16 (current min is 8): android.widget.ImageButton # setBackground you look at what happens
---- - reference ---------------------------------------
I found the problem, is the minimum version is too low, but I changed to 16 after the procedure, while there is no problem, but when running on the phone out of the question, showing encounter "I'm sorry, xxxx has stopped running" What is this rhythm, who can help I answer
------ reference -------------------------------------- -
program problems windows did not have any questions, speed god answer, thank
------ reference -------------------- -------------------
exception see detailed log ah learn joy to own one, had not yet learned to see the log,
------ reference --------------------- ------------------
machine's version is too low to put this function is not supported setbackground
没有评论:
发表评论