I want to add view into my main view....
my main.xml file...
<LinearLayout
android:id="@+id/dynamicview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.28"
android:gravity="center_vertical"
android:orientation="vertical" >
</LinearLayout>
I have another layout file call complete.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
I want to add this web view into linearlayout....it means I want to inflate webview into my mainactivity...
I used the following method...
LinearLayout dynamic=(LinearLayout)findViewById(R.id.dynamicview);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = (FrameLayout) inflater.inflate(R.layout.complete, null);
v.setBackgroundColor(Color.GREEN);
v.getRootView();
dynamic.addView(v);
v.setVisibility(View.VISIBLE);
but this doesn't work. if this is correct then color must be change...but nothing happened. pls help me.. I'm stuck with this...
thanks
Try this:
LinearLayout dynamic=(LinearLayout)findViewById(R.id.dynamicview);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = (FrameLayout) inflater.inflate(R.layout.complete, null);
WebView wv = (WebView)v.findViewById(R.id.webView1);
wv.setBackgroundColor(Color.GREEN);
v.getRootView();
dynamic.addView(v);
v.setVisibility(View.VISIBLE);
You were trying to change the colour of the FrameLayout which has been filled by WebView therefore the green colour won't be visible. Instead, you have to change the colour of the WebView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With