At first I try this way . And I get stuck then, I ask a question, but no one gives any answer. Then I will try another method suggested by @ sayed.jalil in this link . But my application stops working. If someone provides an answer for the first link. And if someone wants to answer the alternative, I tried according to @ sayed.jalil's answer. For this, my code below is
Xml code -
<com.info.abc.JustifiedTextView android:id="@+id/textview1" android:textColor="#FFFFFF"/>
Operation code -
JustifiedTextView txtViewEx = (JustifiedTextView) findViewById(R.id.textview1); txtViewEx.setText("some text");
JustifiedTextView.java -
import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Color; import android.text.SpannableString; import android.webkit.WebChromeClient; import android.webkit.WebView; public class JustifiedTextView extends WebView { private String core = "<html><body style='text-align:justify;color:rgba(%s);font-size:%dpx;margin: 10px 10px 10px 10px;'>%s</body></html>"; private String textColor = "0,0,0,255"; private String text = ""; private int textSize = 12; private int backgroundColor = Color.TRANSPARENT; public JustifiedTextView(Context context) { super(context); this.setWebChromeClient(new WebChromeClient() { }); } public void setText(String s) { this.text = s;
Logcat -
01-19 10:43:19.400: E/AndroidRuntime(1482): FATAL EXCEPTION: main 01-19 10:43:19.400: E/AndroidRuntime(1482): Process: com.info.abc, PID: 1482 01-19 10:43:19.400: E/AndroidRuntime(1482): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.info.abc/com.info.abc.History}: android.view.InflateException: Binary XML file line
android textview justify logcat
John r
source share