0

我目前正在使用此代码为小部件文本视图分配颜色和不透明度:

remoteViews.setTextColor(R.id.nextAlarm_textview, Color.parseColor(text_opacity + text_color));

现在我想对小部件的背景做同样的事情。那可能吗?我尝试了这样的事情,但它不起作用(无效的 int):

remoteViews.setInt(R.id.widget_relative, "setBackgroundColor", Integer.parseInt(background_opacity + background_color));

background_opacity 是#FF,例如 background_color 是 000000。两者都是字符串。

/编辑:

> 08-24 19:28:48.964  15059-15059/com.widget E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.widget, PID: 15059
    java.lang.NumberFormatException: Invalid int: "#FFFFFFFF"
            at java.lang.Integer.invalidInt(Integer.java:137)
            at java.lang.Integer.parse(Integer.java:374)
            at java.lang.Integer.parseInt(Integer.java:365)
            at java.lang.Integer.parseInt(Integer.java:331)
     at com.widget.WidgetSettings$10.onClick(WidgetSettings.java:256)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
            at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0