Thursday, January 23, 2014

The method setBackgroundDrawable (Drawable) from the type View is deprecated solving


            
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;
}
});
}
}



Which hit the middle of a horizontal line setBackgroundDrawable function can not be used, and why?

Reply:
use setBackground (Drawable) instead,
In other setBackground method ah
Hit the 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 an alternative to the use of the function setBackground
Reply:
cited a floor majaw reply:
use setBackground (Drawable) instead,
In other setBackground method ah
Hit the 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 an alternative function setBackground to use


Right or wrong, the error Call requires API level 16 (current min is 8): android.widget.ImageButton # setBackground you look at what happens
Reply:
I found the problem, is the minimum version too, but I changed to 16 after the program although there is no problem, but when running on the phone out of the question, showing encounter "I'm sorry, xxxx has stopped running," This is what rhythm, who can help me answer
Reply:
Program problems windows did not have any questions, great God speed to answer, thank you
Reply:
reference to the third floor yicanday5 reply:
I found the problem, is the minimum version too, but I changed to 16 after the program although there is no problem, but the 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 me

See detailed log of abnormal ah
Reply:
references, 5th Floor majaw reply:
Quote: references to the third floor yicanday5 reply:

I found the problem, is the minimum version too, but I changed to 16 after the program although there is no problem, but when running on the phone out of the question, showing encounter "I'm sorry, xxxx has stopped running," This is what rhythm, who can help me answer

Unusual to see a detailed log ah
own a joy to learn, not learn to look at the log,,,
Reply:
Version of the machine is too low to put this function is not supported setbackground
Reply:
In API16 After this function has been abandoned, please use setBackground instead. You can take a look at tips, sometimes tips are very useful.
Reply:
Your phone also did not support API16

No comments:

Post a Comment