当前位置: 代码迷 >> Android >> The method setBackgroundDrawable(Drawable) from the type View is deprecated求解,该怎么解决
  详细解决方案

The method setBackgroundDrawable(Drawable) from the type View is deprecated求解,该怎么解决

热度:163   发布时间:2016-04-28 06:42:24.0
The method setBackgroundDrawable(Drawable) from the type View is deprecated求解
代码如下
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函数中间打了一条横线,不能被用,为什么?

------解决方案--------------------
引用:
我找到问题了,是最低版本太低,可是我改为16后程序虽然是没有问题了,但是在手机上运行的时候出了问题,显示遇到“很抱歉,xxxx已经停止运行”这是什么节奏,谁能帮我解答

看异常的詳細日志啊
  相关解决方案