In this video it shows the code to convert the TextView to WebView using the HTML MIME type in WebView.loadData API.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
package com.programmerworld.textviewtowebview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
textView = findViewById(R.id.textView);
}
public void buttonGTextViewToWebView(View view){
String stringTextView = textView.getText().toString();
webView.loadData(stringTextView, "text/html", "UTF-8");
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a sample TextView Content to be displayed on WebView - Programmer World"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.177" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="128dp"
android:layout_marginTop="32dp"
android:onClick="buttonGTextViewToWebView"
android:text="TextView to WebView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="@+id/webView"
android:layout_width="304dp"
android:layout_height="373dp"
android:layout_marginStart="53dp"
android:layout_marginTop="35dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshots:
Excerpt:
The video demonstrates how to convert a TextView to a WebView using the loadData API in HTML MIME type. This conversion is performed using the Java package com.programmerworld.textviewtowebview by creating a ‘MainActivity’ class with TextView and WebView properties. Then, in a method called ‘buttonGTextViewToWebView’, the TextView is converted into a string and loaded as ‘text/html’ into the WebView. The corresponding XML design layout uses a ConstraintLayout containing a TextView, Button, and WebView. For queries or suggestions, viewers can contact through the given website or email.
Sir, Please Help me. what should i do? i tried your video- “https://youtu.be/8Sbk-WiZTI0” this to my desktop version after your process my environment turn like Tab Version. there is no Maximize minimize Multiple windows. i want to install play store to my Desktop version not changing to Tab Mode. please reply.
Steps are given in the below page. Please follow the steps. It should work.
https://programmerworld.co/android/enable-google-playstore-in-emulator-avd-android-virtual-device-in-android-studio/