android - Theme/Style is not applied when inflater used with ApplicationContext -


I have a theme that specifies textColor as text for textView.

The problem I am using TextView for using LayoutInflater is that the styles do not apply to TextView when Inflator is created using ApplicationContext - the color is not red

Why this happens, and how can it be decided?

/res/values/styles.xml:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Resources & gt; & Lt; Style name = "Myself" & gt; & Lt; Item name = "android: textViewStyle" gt; @ Style / MyTextView & lt; / Item & gt; & Lt; / Style & gt; & Lt; Style name = "MyTextView" parent = "@ android: style / widget.TextView" & gt; & Lt; Item name = "android: textcolor" & gt; # F00 & lt; / Item & gt; & Lt; / Style & gt; & Lt; / Resources & gt; Android: label = "@ string / app_name" Android:  

Android Manifest. XML:

  Android: Theme = "@ Style / Myself" & gt;  

code:

  increases the public category A activity {@ override protected void creatives (bundle saved instanestate) {super.onCreate (savedInstanceState) ; SetContentView (R.layout.test_a); Final LayoutInflator Good Inflator = Matching Inflator (Activity) This); Final LayoutInfinternetBinFilter = getInflater (getApplicationContext ()); Final Linear Layout Container = (Linear Loyalty) Find VVBID (RID Container); FindViewById (R.id.add_with_appContext) .setOnClickListener {@Override Click Public Zero (see V) {add (container, badInflater); // makes Gray TextView}}); FindViewById (R.id.add_with_activity) .setOnClickListener (New OnClickListener) {@Override Click Public Zero (see V) {add (Container, Good Inflator); // makes RED TextView}}); } Private LayoutsInflater getInflater (Reference Reference) {Return (LayoutInflater) context.getSystemService (Reference. LEOUT_INFLATER_SERVICE); } Private Zero Zodiac (Linear Lloyalty Container, Layout Inflator Inflator) {inflater.inflate (R.Latite.m_template, Container, True); }}  

/res/layout/test_a.xml

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: orientation = "vertical" & gt; & Lt; Android: text = "Add to AppContext" Android: id = "@ + id / add_with_appContext" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> & Lt; Button Android: Text = "Add to Activity" Android: id = "@ + id / add_with_activity" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> & Lt; LinearLayout Android: id = "@ + id / container" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: orientation = "vertical" /> & Lt; / LinearLayout & gt;  

/res/layout/my_template.xml:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" & gt; & Lt; TextView Android: id = "@ + id / text" Android: text = "some text ..." Android: layout_width = "fill_parent" android: layout_height = "wrap_content" /> & Lt; / LinearLayout & gt;  

solution # 1

Flight method accepts the optional 'View Group Route' argument:

  View public footage (Intro Resources, View Group Route, Boolean Attic)  

If our Pass the pass value as the 'root' parameter, so we can use it to get 'activity reference' from which we can get the layout indicator:

  ViewGroup root & Gt; Activity reference & gt; Layout Inflator  

Then my code can be:

  Private zeros additive (linear layout container) {layout infletter inflater = getInflater (container.getContext () ); Inflater.inflate (R.layout.my_template, Container, True); }  

Resolution # 2

Just tried to set up a program context program, and it works :

  getApplicationContext (). Settheme (r. style mythim);  

I think it was logical to expect the markup:

   

To set it up automatically, but it is not.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -