आप के निर्माता को देखना शैली पारित कर सकते हैं के लिए। इसके लिए एक विषय के रूप में
उपयोग ContextThemeWrapper
और सेटअप अपनी शैली: यह 2 तरीकों में किया जा सकता
ContextThemeWrapper wrappedContext = new ContextThemeWrapper(yourContext, R.style.test);
TextView testView = new TextView(wrappedContext, null, 0);
और महत्वपूर्ण नोट यहाँ - ठीक से ContextThemeWrapper
साथ शैली स्थापित करने के लिए हम तीन-तर्क कन्स्ट्रक्टर का उपयोग करना होगा और defStyleAttr
पैरामीटर 0 पर सेट करना होगा अन्यथा डिफ़ॉल्ट बटन शैली दृश्य पर लागू की जाएगी।
हम 4 मानकों के साथ निर्माता का उपयोग कर सकते एपीआई 21 से शुरू:
View (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
कहाँ defStyleRes
एक ही टिप्पणी के साथ अपनी शैली आईडी
है - defStyleAttr 0
होना चाहिए आप इस जवाब को स्टैक ओवरफ़्लो http://stackoverflow.com/a/ पर देख सकते हैं 3224365/1769515 –