(Android app development question) How do I set the style resource of a LinearLayout in Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

(Android app development question) How do I set the style resource of a LinearLayout in Java?

So I have a LinearLayout in my XML layout file and in my activity with an ID of "layout". In my Java Activity, I have a variable that is LinearLayout l = findViewById(R.id.layout). I want to add another LinearLayout to "l" using the "addView" method. I want the LinearLayout I am adding to "l" to have the style of a style in the "styles.xml" file. How do I do that?

22nd Oct 2019, 10:42 PM
androidCoder255
androidCoder255 - avatar
1 Answer
+ 1
While constructing object of Linear Layout pass the Style reference as 3rd parameter: `LinearLayout childOfL = new LinearLayout(this, null, R.style.myLinearLayoutStyle);`
1st Feb 2020, 9:50 PM
Ameer Hamza Naveed
Ameer Hamza Naveed - avatar