【问题标题】:setCompoundDrawables with RemoteViews带有 RemoteViews 的 setCompoundDrawables
【发布时间】:2017-09-13 16:03:09
【问题描述】:

我有一个带有 textview 和 imageview 的 appwidget 布局。

Lint 总是告诉我用复合文本视图替换它。

问题是,如何使用 RemoteViews 调用 setCompoundDrawables? 有可能吗?

谢谢。

更新: http://code.google.com/p/android/issues/detail?id=29249

【问题讨论】:

  • 我不记得我是如何做到的,也不记得它是否相关,但是一旦我将一个方法注释为“@Remotable”并且以后能够调用它。不确定在这种情况下是否有帮助。否则,我看不出有任何其他方法可以做到。

标签: android android-appwidget


【解决方案1】:

【讨论】:

    【解决方案2】:

    当你使用 setCompoundDrawables 时,你需要这样的代码:

    Drawable img;
    Resources res = getResources();
    img = res.getDrawable(R.drawable.btn_img);
    //You need to setBounds before setCompoundDrawables , or it couldn't display
    img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());
    btn.setCompoundDrawables(img_off, null, null, null); 
    

    所以你必须有方法调用getResources()! 您可以将 Activity 上下文作为参数传递以使用 getResources() 和 findViewById。

    【讨论】:

    • getResources 不是问题。 RemoteViews 没有 setCompoundDrawables 方法。我目前的答案是不可能。也许在软糖里..
    【解决方案3】:

    使用 setTextViewCompoundDrawables

    contentiew.setTextViewCompoundDrawables(R.id.setting_btn, 0, R.mipmap.ic_gray_setting,0,0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多