मैं एक ऐपविड्ज बनाने की कोशिश कर रहा हूं, जिसमें टेक्स्ट व्यू का पृष्ठभूमि रंग निर्दिष्ट आवधिक अंतराल पर यादृच्छिक रूप से बदलता है।एंड्रॉइड ऐपविजेट टेक्स्ट व्यू: रन टाइम पर पृष्ठभूमि रंग कैसे सेट करें
TextView के रूप में
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/message"
android:background="#ff99ff"
android:text="Hello Widget" />
</LinearLayout>
अद्यतन विधि में लेआउट xml फ़ाइल में परिभाषित किया गया है, मैं
RemoteViews remoteView=new RemoteViews(context.getPackageName(),R.layout.widget_message);
के रूप में लेआउट लोड TextView की पृष्ठभूमि मैं निम्नलिखित बयान का इस्तेमाल किया बदलने के लिए
remoteView.setInt(R.id.message, "setBackgroundResource", R.color.col_1);
लेकिन मुझे विजेट लोड करने में समस्या कह रही है। अगर मैं उपर्युक्त रेखा को हटा देता हूं तो सब कुछ ठीक काम करता है।
LogCat का कहना है:
updateAppWidget, किसी भी दृश्य नहीं पा सके त्रुटि दृश्य का उपयोग कर
android.widget.RemoteViews $ ActionException: दृश्य: android.widget.TextView नहीं कर सकते उपयोग RemoteViews साथ विधि: setBackgroundResource (int)
बिल्कुल। आप केवल उन विधियों का उपयोग कर सकते हैं जिनमें @RemotableViewMethod एनोटेशन –