如何禁用远程视图中的按钮?

Tam*_*ári 1 android

我可以使用下面的代码使它不可见,但是不能禁用它。

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
contentView.setViewVisibility(R.id.buttonToDisable, View.INVISIBLE);
Run Code Online (Sandbox Code Playgroud)

Com*_*are 5

setEnabled()@RemotableViewMethod,至少在源代码的当前master分支上。因此,您应该可以使用setBoolean()

contentView.setBoolean(R.id.buttonToDisable, "setEnabled", false);
Run Code Online (Sandbox Code Playgroud)

  • @TamásBolvári:是的,有时,他们会将该注释添加到以前没有该注释的方法中。您唯一的其他选择是拥有两个布局资源,一个启用按钮,另一个禁用按钮。 (2认同)