在Android Webview中对齐文本

问题描述:

我在我的应用程序中有一个WebView。我想将它中的文本从右到左对齐。我尝试添加:在Android Webview中对齐文本

 <WebView 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:layout_margin="@dimen/spacing_xsmall" /> 

这是我的代码

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:orientation="vertical" 
     android:padding="@dimen/spacing_middle" 
     android:visibility="visible"> 

     <TextView 
      android:id="@+id/category" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end" 
      android:background="@color/colorAccentLight" 
      android:paddingBottom="@dimen/spacing_xsmall" 
      android:paddingLeft="@dimen/spacing_medium" 
      android:paddingRight="@dimen/spacing_medium" 
      android:paddingTop="@dimen/spacing_xsmall" 
      android:text="Category" 
      android:textAllCaps="true" 
      android:textAppearance="@style/TextAppearance.AppCompat.Body1" 
      android:textColor="@android:color/white" /> 

    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/grey_soft" 
     android:paddingBottom="@dimen/spacing_large" 
     android:paddingTop="@dimen/spacing_middle"> 

     <WebView 
      android:id="@+id/content" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/spacing_xsmall" /> 

    </RelativeLayout> 

但是,这并不为我工作。 textview工作正常,但WebView无法正常工作? 我该如何解决问题

谢谢。

Android中的webview用于显示网页。它按照原样显示网页中的数据。

如果您想更改网页的文本对齐方式,您必须从网站执行(假设您有权访问该网页)。