4

I have a WebView in my application. I want to align the text in it to from right to left . I tried adding:

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

this is my code

    <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>

But this doesn't work for me. the textview work fine but the WebView not working ?? How can i resolve the issues

thank you.

  • It does not solve my problem but can help recreate it using right justification https://mobikul.com/align-justify-text-android/ – CrandellWS Sep 30 '18 at 10:08
  • been loading dynamic data turns out after making logs I realized the problem was escaping... https://stackoverflow.com/a/18898904/1815624 for testing `str.replace("\\\"", "\"")` gave me right aligned results... – CrandellWS Sep 30 '18 at 10:35

1 Answers1

0

The webview in Android is used to display web pages. It displays the data in web page as it is.

If you want to change text alignment of the web page, you will have to do it from the website (assuming you have access to that).