पर आधारित एटआर रंग मान प्राप्त करें मेरी गतिविधि में मैं रख रहा हूं, जिसमें मैं थीम सेट कर रहा हूं।वर्तमान सेट थीम
public class SuperActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MyTheme);
}
}
themes.xml
<!-- ImageBackround -->
<style name="Theme.MyTheme" parent="ThemeLight">
<item name="myBgColor">@color/translucent_black</item>
</style>
अब मैं अपने बच्चे गतिविधि का एक में इस रंग लाने के लिए चाहते हैं।
इस संभावित answer में उल्लेख किया है, मैं ने लिखा है:
int[] attrs = new int[] { R.attr.myBgColor /* index 0 */};
TypedArray ta = ChildActivity.this.obtainStyledAttributes(attrs);
int color = ta.getColor(0, android.R.color.background_light);
String c = getString(color);
ta.recycle();
लेकिन हर मैं android.R.color.background_light
& R.attr.myBgColor
की नहीं का डिफ़ॉल्ट मान का मूल्य हो रही है।
जहां मैं गलत कर रहा हूं। क्या मैं ChildActivity.this
के गलत संदर्भ को पार कर रहा हूं?
अंत में, एक जवाब जो बॉक्स से बाहर काम करता है! – kirtan403