如何调用getDrawable方法 [英] How to call getDrawable method

查看:173
本文介绍了如何调用getDrawable方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的图像共享应用程序,它使用一键分享图片。我发现了一个未能解​​决所需的方法误差在下面的code:

I am creating an image sharing app which uses a button to share images. I'm getting an unable to resolve the required method error in the code below:

public class ShareActivity extends Activity implements View.OnClickListener {

    Button button1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);

        button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(this);
    }
    private void button1Click()
    {
        BitmapDrawable bm = (BitmapDrawable) getDrawable(button1);
        Bitmap mysharebmp = bm.getBitmap();
        String path = Images.Media.insertImage(getContentResolver(),
                            mysharebmp, "MyImage", null);

在这一行:

BitmapDrawable bm = (BitmapDrawable) getDrawable(button1);ShareActivity

我收到的方法getDrawable(巴顿)是未定义的类型ShareActivity 。为什么会我会得到这个错误?满code是<一个href="http://stackoverflow.com/questions/21955943/share-the-selected-image-only-in-android">here.

I am getting The method getDrawable(Button) is undefined for the type ShareActivity. Why might I be getting this error? The full code is here.

推荐答案

这是非常不清楚,你想在这里做什么,我怀疑你会遇到其他一些问题,这code。但你得到getDrawable是未定义ShareActivity错误的原因是因为活动类没有一个 getDrawable 方法。

It's extremely unclear as to what you want to do here, and I suspect you're going to encounter a number of other problems with this code. But the reason that you're getting the error "getDrawable is undefined for ShareActivity" is because the Activity class does not have a getDrawable method.

而不是调用 getDrawable 中,你需要获得应用程序的资源,然后检索的绘制。你要找的是什么:

Instead of calling getDrawable, you need to get the app resources and then retrieve the drawable. What you're looking for is:

BitmapDrawable bm = (BitmapDrawable) getResources().getDrawable(R.drawable.my_bitmap);

如果你有一些图像被称为my_bitmap.png在 / RES /绘制/

这篇关于如何调用getDrawable方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆