Skip to content Skip to sidebar Skip to footer

How To Set Webview Content In Center?

I am loading some HTML content in WebView but its always coming in the top left corner of my WebView. I have tried to use stylesheet also, in stylesheet I have added center related

Solution 1:

try this:

<html><head><styletype="text/css">@font-face { font-family: MyCustomFont;  
src:url("~/android_asset/fonts/MyriadPro-Regular.otf") } 
#text{ font-family: MyCustomFont; 
font-size:14; 
text-align: center;
margin:350px;
line-height: normal;
color:blue;
height:20px;
width:100px;
margin:auto;
background-color:red;
} 
</style></head><body><pid="text"> Hello World</p></body></html>

And I think that your address source font is mistake!

Solution 2:

<WebView android:id="@+id/webview1" 
  android:layout_gravity="center"
  android:scaleType="centerInside"
  android:layout_width="wrap_content" 
  android:layout_height="fill_parent"
  android:adjustViewBounds="true">

it might help you.

Post a Comment for "How To Set Webview Content In Center?"