【问题标题】:using R.drawable in titanium module for android在用于 android 的钛模块中使用 R.drawable
【发布时间】:2013-09-09 18:33:07
【问题描述】:

我正在尝试创建一个模块(Android 的本机服务),以便我的 appcelerator 应用程序可以启动本机服务。该服务运行良好,它创建了一个 relativeLayout 一个 system_overlay 我可以设置该 relativeLayout 的背景颜色,但最终我想设置它的 backgroundImage。我有一个要用于该背景的 png,名为:bg_noti

我曾尝试在我的本机服务类(模块项目内部)中这样做:

String bg_name ="android.R.drawble.bg_noti";
        try {
            notificationBar.setBackgroundResource(TiRHelper.getApplicationResource(bg_name));
        } catch (ResourceNotFoundException e) {
            // TODO Auto-generated catch block
            Log.v(":::::::::::", "EXCEPTION:"+e);
            e.printStackTrace();
        }

我的理解是我需要将 png 放在 Titanium 应用程序项目中的某个位置,但无论我把它放在哪里,它似乎都不会进入编译后的应用程序..

我总是得到资源未找到的异常。

我按照此处找到的示例进行操作:http://developer.appcelerator.com/question/49671/android-r-references-in-appcelerator-module

但他们说将图像放在不存在的 $APP_DIR/platform/android/res 目录中..我尝试创建它...但仍然无法正常工作..

有人可以告诉我我实际上应该将这张图片放在钛应用项目中的什么位置,以便模块可以引用它。

【问题讨论】:

    标签: titanium titanium-modules


    【解决方案1】:

    您使用了getApplicationResource 方法,但您想要一个Android 资源。您应该尝试使用getAndroidResource 方法:

    String bg_name = "drawble.bg_noti";
    try {
        notificationBar.setBackgroundResource(TiRHelper.getAndroidResource(bg_name));
    } catch (ResourceNotFoundException e) {
        …
    }
    

    您还应该将bg_nameandroid.R.drawable.bg_noti 更改为drawble.bg_noti)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 1970-01-01
      相关资源
      最近更新 更多