Home > Software engineering >  Navigation to local HTML Android Studio
Navigation to local HTML Android Studio

Time:07-09

The idea is to make the link (in this photo) navigate to a local HTML:

Photo

So when you click on Privacy Policy, it opens the local HTML.

This message is stored in an strings.xml code like this:

<string name="eula">Check our <a href="./hosp_eula.html" style="color: #00808f;">Privacy Policy</a></string>

And in the layout i reference to it like this:

<TextView
                        android:id="@ id/eulaText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="20dp"
                        android:layout_marginTop="30dp"
                        android:fontFamily="@font/tahoma"
                        android:text="@string/eula"
                    android:textColor="@color/color_hintTextColor_formulario"
                    android:textSize="18sp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@ id/text_eula_header" />

But it doesn't work due to the fact that i don't know how to make reference to the HTML file located in this root:

eula/hosp_eula.html

I've also tried to put that on the tag, but had no luck.

CodePudding user response:

try to use, Span is recommended by google to add style to TextView and make text clickable [1]: https://developer.android.com/guide/topics/text/spans then use WebView to load private policy on click, you can follow How to load html string in a webview? question to do that

CodePudding user response:

You can't display HTML page directly on your Activity.

XML

   android:id="@ id/webview"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
/>

CODE

WebView browser = (WebView) findViewById(R.id.webview);
browser.loadUrl("./hosp_eula.html");

This website helps you to learn more about WebView Learn from here - https://www.tutorialspoint.com/android/android_webview_layout.htm

Make sure that, your html file is located in res>raw (folder), if it doesn't having raw folder, then create it.

Right click on res folder pic
  • Related