Note that there are some explanatory texts on larger screens.

plurals
  1. POsetting the background colour from program rather than from xml for fragments
    primarykey
    data
    text
    <p>I need some help in setting the background colour using code for my current fragment. The fragment is created on selecting a particular tab.</p> <p>Below is my main activity code</p> <pre><code>public class TabActionBarActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the text and background colour setTheme(R.style.MyTheme); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); String label6 = getResources().getString(R.string.label6); tab = actionBar.newTab(); tab.setText(label6); TabListener&lt;Tab6Fragment&gt; tl6 = new TabListener&lt;Tab6Fragment&gt;(this, label6, Tab6Fragment.class); tab.setTabListener(tl6); actionBar.addTab(tab); String label7 = getResources().getString(R.string.label7); tab = actionBar.newTab(); tab.setText(label7); TabListener&lt;Tab7Fragment&gt; tl7 = new TabListener&lt;Tab7Fragment&gt;(this, label7, Tab7Fragment.class); tab.setTabListener(tl7); actionBar.addTab(tab); } </code></pre> <p>Now the code for the Tab7Fragment class looks like this</p> <pre><code> public class Tab7Fragment extends Fragment { TextView tv1; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ScrollView sv = new ScrollView(this.getActivity()); LinearLayout ll = new LinearLayout(this.getActivity()); ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll); TextView tv = new TextView(this.getActivity()); tv.setText("Dynamic layouts ftw!"); ll.addView(tv); EditText et = new EditText(this.getActivity()); et.setText("weeeeeeeeeee~!"); ll.addView(et); Button b = new Button(this.getActivity()); b.setText("I don't do anything, but I was added dynamically. :)"); ll.addView(b); for(int i = 0; i &lt; 20; i++) { CheckBox cb = new CheckBox(this.getActivity()); cb.setText("I'm dynamic!"); ll.addView(cb); } return this.getView(); } </code></pre> <p>}</p> <p>Now how can i set the view for this fragment?</p> <pre><code>this.getActivity().setContentView(sv); </code></pre> <p>I know the above method is incorrect. But i need to set the content view with the scrollview layout. and another question is how do i set the background colour for this view?(using setBackgroundColor()?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload