如何以编程方式禁用的Android AppWidget按钮的onClick处理程序
我有appwidget一个按钮,我需要从服务到启用/禁用编程。
I have a Button on appwidget, that I need to 'enable'/'disable' programmatically from a Service.
最初的想法是叫 setBoolean(R.id.buttonid,setClickable,FALSE)
来禁用它,但显然你不能叫 setClickable
远程
First idea was to call setBoolean(R.id.buttonid, "setClickable", false)
to disable it, but apparently you can't call setClickable
remotely.
另一个想法是来自它 rv.setTextViewText删除文本标签(R.id.buttonid,)
,然后通过 rv.setOnClickPendingIntent(R.id.buttonid,空)。不幸的是通过空
来它会导致 NullPointerException异常
在 android.app.ActivityThread.handleServiceArgs
Another idea was was remove the text label from it with rv.setTextViewText(R.id.buttonid, "")
and then remove the click handler by rv.setOnClickPendingIntent(R.id.buttonid, null)
. Unfortunately passing null
to it causes NullPointerException
in in android.app.ActivityThread.handleServiceArgs
有一些其他的方式来编程禁用/启用appwidget按钮?我可以叫 rv.setViewVisibility(R.id.buttonid,View.GONE)
来隐藏按钮完全不是禁用它。这将然而,彻底打破整个部件的布局,我想避免它。
Is there some other way to programmatically disable/enable appwidget Button? I could just call rv.setViewVisibility(R.id.buttonid, View.GONE)
to hide the button completely instead of disabling it. This would however completely break whole widget layout and I would like to avoid it.
我现在使用的溶液与 setViewVisibility
隐藏按钮,而是显示其他空白按钮保持appwidget布局,因为它以前。
The solution I'm using now is hiding the button with setViewVisibility
and showing other blank button instead to the keep appwidget layout as it was before.
当您创建 RemoteViews
例如,你提供一个布局。当您希望禁用的按钮,选择与 Android的布局:启用=FALSE
该按钮
When you create your RemoteViews
instance, you supply a layout. When you want to disable the button, choose a layout with android:enabled="false"
on that button.
或者,你可以使用 setOnClickPendingIntent()
并提供一个意图
,就不会去任何地方(例如,广播意图
为无人使用的动作)。
Or, you could use setOnClickPendingIntent()
and supply an Intent
that just will not go anywhere (e.g., a broadcast Intent
for an action that nobody uses).