【问题标题】:Android How can i change the background on a button click event?Android 如何更改按钮单击事件的背景?
【发布时间】:2012-01-26 22:06:12
【问题描述】:

我想在单击事件上更改小部件按钮的背景,然后返回原始背景,例如 ACTION_DOWN 和 ACTION_UP。 我知道我可以改变背景:

RemoteViews.setInt(viewId, methodName, value);

并为点击事件添加一个动作:

Intent intent = new Intent(context, MyWidget.class);
intent.setAction("Restart");
PendingIntent pIntent = PendingIntent.getBroasdcast(context, 0, intent, 0);
RemoteViews.setOnClickPendingIntent(viewId, pIntent);

【问题讨论】:

  • 选择器不能与远程视图一起使用???

标签: android android-widget widget


【解决方案1】:

查看 StateList xml 文件。这些文件使用的选择器将处理在所有各种状态下更改视图的背景,您不必为编写自己的触摸监听器而烦恼。

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 2017-02-19
    相关资源
    最近更新 更多