Files
PanguText/assets/android.html-XQpTmuqf.js
github-actions[bot] 96f689cf92 Deploy to GitHub pages
2025-08-19 07:59:07 +00:00

172 lines
56 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{_ as o,r as t,o as i,c as p,a as e,b as s,d as l,e as n}from"./app-6WmjFGj_.js";const c={},r=n(`<h1 id="android" tabindex="-1"><a class="header-anchor" href="#android" aria-hidden="true">#</a> Android</h1><p><img src="https://img.shields.io/maven-central/v/com.highcapable.pangutext/pangutext-android?logo=apachemaven&amp;logoColor=orange&amp;style=flat-square" alt="Maven Central"><span style="margin-left:5px;"></span><img src="https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fraw.githubusercontent.com%2FHighCapable%2Fmaven-repository%2Frefs%2Fheads%2Fmain%2Frepository%2Freleases%2Fcom%2Fhighcapable%2Fpangutext%2Fpangutext-android%2Fmaven-metadata.xml&amp;logo=apachemaven&amp;logoColor=orange&amp;label=highcapable-maven-releases&amp;style=flat-square" alt="Maven metadata URL"><span style="margin-left:5px;"></span><img src="https://img.shields.io/badge/Min SDK-21-orange?logo=android&amp;style=flat-square" alt="Android Min SDK"></p><p>This is the core dependency for the Android platform. When using <code>PanguText</code> on Android, you need to include this module.</p><h2 id="configure-dependency" tabindex="-1"><a class="header-anchor" href="#configure-dependency" aria-hidden="true">#</a> Configure Dependency</h2><p>You can add this module to your project using the following method.</p><h3 id="sweetdependency-recommended" tabindex="-1"><a class="header-anchor" href="#sweetdependency-recommended" aria-hidden="true">#</a> SweetDependency (Recommended)</h3><p>Add dependency in your project&#39;s <code>SweetDependency</code> configuration file.</p><div class="language-yaml line-numbers-mode" data-ext="yml"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#8DDB8C;">libraries</span><span style="color:#ADBAC7;">:</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#8DDB8C;">com.highcapable.pangutext</span><span style="color:#ADBAC7;">:</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#8DDB8C;">pangutext-android</span><span style="color:#ADBAC7;">:</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#8DDB8C;">version</span><span style="color:#ADBAC7;">: </span><span style="color:#96D0FF;">+</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Configure dependency in your project&#39;s <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">implementation</span><span style="color:#ADBAC7;">(com.highcapable.pangutext.pangutext.android)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="version-catalog" tabindex="-1"><a class="header-anchor" href="#version-catalog" aria-hidden="true">#</a> Version Catalog</h3><p>Add dependency in your project&#39;s <code>gradle/libs.versions.toml</code>.</p><div class="language-toml line-numbers-mode" data-ext="toml"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">[</span><span style="color:#F69D50;">versions</span><span style="color:#ADBAC7;">]</span></span>
<span class="line"><span style="color:#ADBAC7;">pangutext-android = </span><span style="color:#96D0FF;">&quot;&lt;version&gt;&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">[</span><span style="color:#F69D50;">libraries</span><span style="color:#ADBAC7;">]</span></span>
<span class="line"><span style="color:#ADBAC7;">pangutext-android = { module = </span><span style="color:#96D0FF;">&quot;com.highcapable.pangutext:pangutext-android&quot;</span><span style="color:#ADBAC7;">, version.ref = </span><span style="color:#96D0FF;">&quot;pangutext-android&quot;</span><span style="color:#ADBAC7;"> }</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Configure dependency in your project&#39;s <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">implementation</span><span style="color:#ADBAC7;">(libs.pangutext.android)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Please change <code>&lt;version&gt;</code> to the version displayed at the top of this document.</p><h3 id="traditional-method" tabindex="-1"><a class="header-anchor" href="#traditional-method" aria-hidden="true">#</a> Traditional Method</h3><p>Configure dependency in your project&#39;s <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">implementation</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;com.highcapable.pangutext:pangutext-android:&lt;version&gt;&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Please change <code>&lt;version&gt;</code> to the version displayed at the top of this document.</p><h2 id="function-introduction" tabindex="-1"><a class="header-anchor" href="#function-introduction" aria-hidden="true">#</a> Function Introduction</h2>`,21),d={href:"https://betterandroid.github.io/PanguText/KDoc/pangutext-android",target:"_blank",rel:"noopener noreferrer"},u=n(`<h3 id="implementation-principle" tabindex="-1"><a class="header-anchor" href="#implementation-principle" aria-hidden="true">#</a> Implementation Principle</h3><p><code>PanguText</code> provides two methods for text formatting on the Android platform: <code>SpannableString</code> (does not alter the original text length) and direct insertion of whitespace characters (alters the original text length).</p><p>The first method, <code>SpannableString</code>, adds a <code>Span</code> with spacing to the character before the one that needs spacing, changing the text style without altering the string content. The rendering is done by the <code>TextView</code> layer (or manually using <code>TextPaint</code> based on <code>Spanned</code> for layout styling), achieving non-intrusive text styling.</p><p>This method also supports processing already styled text (<code>Spanned</code>), such as text created via <code>Html.fromHtml</code>.</p><p><strong>However, it is currently experimental and may still have unexpected style errors</strong>. You can refer to the <a href="#personalized-configuration">Personalized Configuration</a> section below to disable it.</p><p>The dynamic application (injection) feature mainly targets the input state of <code>EditText</code>. It sets a custom <code>TextWatcher</code> for <code>EditText</code> to monitor input changes and formats the text from <code>afterTextChanged</code>.</p><p>The second method directly inserts whitespace characters after the characters that need spacing. This method alters the original text length and content but does not rely on the <code>TextView</code> layer for rendering. It uses <code>TextPaint</code> to draw the text directly, suitable for all scenarios, <strong>but does not support dynamic application (injection)</strong>.</p><div class="custom-container warning"><p class="custom-container-title">Unresolved Issues</p><p><code>PanguText</code> may conflict with Material components like <code>TextInputEditText</code>, <code>MaterialAutoCompleteTextView</code>, and <code>TextInputLayout</code> when using <code>setHint</code>, as <code>TextView</code> does not account for <code>Span</code> during measurement. This issue is particularly noticeable in single-line text, and there is no solution yet. Use these components cautiously.</p><p>Due to the above issue, calculating the width of a <code>TextView</code> with <code>PanguText</code> style using the <code>View.measure</code> method may also result in errors.</p><p><code>PanguText</code> currently cannot handle continuous characters like underlines or strikethroughs in <code>Spanned</code> text, as the lines will break after adding spacing. It may also cause style errors or fail to apply styles correctly to some special characters. For stability, avoid enabling <code>PanguText</code> for very complex rich text or refer to the <a href="#personalized-configuration">Personalized Configuration</a> section to set <code>excludePatterns</code>.</p></div><h3 id="integrate-into-existing-projects" tabindex="-1"><a class="header-anchor" href="#integrate-into-existing-projects" aria-hidden="true">#</a> Integrate into Existing Projects</h3><p>Integrating <code>PanguText</code> into your current project is very easy. You don&#39;t need to change much code. Choose your preferred method below to complete the integration.</p><h4 id="inject-to-layoutinflater" tabindex="-1"><a class="header-anchor" href="#inject-to-layoutinflater" aria-hidden="true">#</a> Inject to LayoutInflater</h4><p><code>PanguText</code> supports direct injection of <code>LayoutInflater.Factory2</code> or creating a <code>LayoutInflater.Factory2</code> instance for the current <code>Activity</code> to take over the entire view layout inflation. This is the recommended integration method, as it allows for non-intrusive and quick integration without modifying any existing layouts.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">MainActivity</span><span style="color:#ADBAC7;"> : </span><span style="color:#F69D50;">AppCompatActivity</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> binding </span><span style="color:#F47067;">by</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">lazy</span><span style="color:#ADBAC7;"> { ActivityMainBinding.</span><span style="color:#DCBDFB;">inflate</span><span style="color:#ADBAC7;">(layoutInflater) }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState: </span><span style="color:#F69D50;">Bundle</span><span style="color:#ADBAC7;">?) {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">super</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Inject here.</span></span>
<span class="line"><span style="color:#ADBAC7;"> PanguTextFactory2.</span><span style="color:#DCBDFB;">inject</span><span style="color:#ADBAC7;">(</span><span style="color:#6CB6FF;">this</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">setContentView</span><span style="color:#ADBAC7;">(binding.root)</span></span>
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>Since <code>LayoutInflater.Factory2</code> is taken over, recycled layouts like <code>ListView</code> and <code>RecyclerView</code> can also be correctly handled.</p><p>After injecting the <code>LayoutInflater</code> instance in the <code>Activity</code>, the following instances attached to the current <code>Context</code> will automatically take effect:</p><ul><li><code>Fragment</code></li><li><code>Dialog</code></li><li><code>PopupWindow</code></li><li><code>Toast</code> (foreground only in higher system versions)</li></ul><p>Layouts based on <code>RemoteView</code> will not take effect because they are remote objects and do not use the current <code>Context</code>&#39;s <code>LayoutInflater</code> for layout inflation.</p></div>`,15),y={href:"https://betterandroid.github.io/BetterAndroid/KDoc/ui-component/ui-component/com.highcapable.betterandroid.ui.component.activity/-app-binding-activity",target:"_blank",rel:"noopener noreferrer"},A=e("code",null,"BetterAndroid",-1),m=n(`<blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">MainActivity</span><span style="color:#ADBAC7;"> : </span><span style="color:#F69D50;">AppBindingActivity</span><span style="color:#ADBAC7;">&lt;</span><span style="color:#F69D50;">ActivityMainBinding</span><span style="color:#ADBAC7;">&gt;() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onPrepareContentView</span><span style="color:#ADBAC7;">(savedInstanceState: </span><span style="color:#F69D50;">Bundle</span><span style="color:#ADBAC7;">?): </span><span style="color:#F69D50;">LayoutInflater</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> inflater </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">super</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">onPrepareContentView</span><span style="color:#ADBAC7;">(savedInstanceState)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Inject here.</span></span>
<span class="line"><span style="color:#ADBAC7;"> PanguTextFactory2.</span><span style="color:#DCBDFB;">inject</span><span style="color:#ADBAC7;">(inflater)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">return</span><span style="color:#ADBAC7;"> inflater</span></span>
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState: </span><span style="color:#F69D50;">Bundle</span><span style="color:#ADBAC7;">?) {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">super</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If your application does not use <code>AppCompatActivity</code> or <code>ViewBinding</code>, don&#39;t worry, you can still use the original method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">MainActivity</span><span style="color:#ADBAC7;"> : </span><span style="color:#F69D50;">Activity</span><span style="color:#ADBAC7;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState: </span><span style="color:#F69D50;">Bundle</span><span style="color:#ADBAC7;">?) {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">super</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Inject here.</span></span>
<span class="line"><span style="color:#ADBAC7;"> PanguTextFactory2.</span><span style="color:#DCBDFB;">inject</span><span style="color:#ADBAC7;">(</span><span style="color:#6CB6FF;">this</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">setContentView</span><span style="color:#ADBAC7;">(R.layout.activity_main)</span></span>
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p><code>PanguTextFactory2</code> can be used not only with <code>Activity</code> but also injected into any existing <code>LayoutInflater</code> instance. However, please inject it before the <code>LayoutInflater</code> instance is used to inflate the layout, otherwise it will not take effect.</p></div><h4 id="using-the-patching-tool" tabindex="-1"><a class="header-anchor" href="#using-the-patching-tool" aria-hidden="true">#</a> Using the Patching Tool</h4><p>You can use <code>PanguTextPatcher</code> to patch existing <code>View</code> or <code>ViewGroup</code> instances.</p><p>Patch the entire root layout, and <code>PanguTextPatcher</code> will automatically patch all <code>TextView</code> instances or their subclasses under the root layout.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume you have a root layout.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> root: </span><span style="color:#F69D50;">ViewGroup</span></span>
<span class="line"><span style="color:#768390;">// Patch the root layout.</span></span>
<span class="line"><span style="color:#ADBAC7;">PanguTextPatcher.</span><span style="color:#DCBDFB;">patch</span><span style="color:#ADBAC7;">(root)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Patch a single <code>View</code>, which is of type <code>TextView</code> or a subclass of <code>TextView</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume this is your TextView.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> textView: </span><span style="color:#F69D50;">TextView</span></span>
<span class="line"><span style="color:#768390;">// Patch a single View.</span></span>
<span class="line"><span style="color:#ADBAC7;">PanguTextPatcher.</span><span style="color:#DCBDFB;">patch</span><span style="color:#ADBAC7;">(textView)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>When using <code>PanguTextPatcher</code> in recycled layouts such as <code>RecyclerView</code>, <code>ListView</code>, or <code>ViewPager</code>, you need to patch the <code>itemView</code> in <code>onCreateViewHolder</code> or <code>onBindViewHolder</code>, otherwise it will not take effect.</p></div><h4 id="manual-injection-or-text-formatting" tabindex="-1"><a class="header-anchor" href="#manual-injection-or-text-formatting" aria-hidden="true">#</a> Manual Injection or Text Formatting</h4><p><code>PanguText</code> also supports manual injection, allowing you to inject it into the desired <code>TextView</code> or <code>EditText</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume this is your TextView.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> textView: </span><span style="color:#F69D50;">TextView</span></span>
<span class="line"><span style="color:#768390;">// Assume this is your EditText.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> editText: </span><span style="color:#F69D50;">EditText</span></span>
<span class="line"><span style="color:#768390;">// Inject into existing text.</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.</span><span style="color:#DCBDFB;">injectPanguText</span><span style="color:#ADBAC7;">()</span></span>
<span class="line"><span style="color:#ADBAC7;">editText.</span><span style="color:#DCBDFB;">injectPanguText</span><span style="color:#ADBAC7;">()</span></span>
<span class="line"><span style="color:#768390;">// Optionally choose whether to inject Hint (default is true).</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.</span><span style="color:#DCBDFB;">injectPanguText</span><span style="color:#ADBAC7;">(injectHint </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">false</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">editText.</span><span style="color:#DCBDFB;">injectPanguText</span><span style="color:#ADBAC7;">(injectHint </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">false</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Dynamic injection, re-calling setText will automatically take effect.</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.</span><span style="color:#DCBDFB;">injectRealTimePanguText</span><span style="color:#ADBAC7;">()</span></span>
<span class="line"><span style="color:#768390;">// Dynamic injection mainly targets the input state of EditText.</span></span>
<span class="line"><span style="color:#ADBAC7;">editText.</span><span style="color:#DCBDFB;">injectRealTimePanguText</span><span style="color:#ADBAC7;">()</span></span>
<span class="line"><span style="color:#768390;">// Optionally choose whether to inject Hint (default is true).</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.</span><span style="color:#DCBDFB;">injectRealTimePanguText</span><span style="color:#ADBAC7;">(injectHint </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">false</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">editText.</span><span style="color:#DCBDFB;">injectRealTimePanguText</span><span style="color:#ADBAC7;">(injectHint </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">false</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><code>PanguText</code> also extends the <code>setText</code> method of <code>TextView</code>, allowing you to directly set text with <code>PanguText</code> style.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume this is your TextView.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> textView: </span><span style="color:#F69D50;">TextView</span></span>
<span class="line"><span style="color:#768390;">// Set text with PanguText style.</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.</span><span style="color:#DCBDFB;">setTextWithPangu</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;Xiaoming今年16岁&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Set Hint with PanguText style.</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.</span><span style="color:#DCBDFB;">setHintWithPangu</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;输入Xiaoming的年龄&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also use the <code>PanguText.format</code> method to directly format text.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume this is your TextView.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> textView: </span><span style="color:#F69D50;">TextView</span></span>
<span class="line"><span style="color:#768390;">// Format text using SpannableString method.</span></span>
<span class="line"><span style="color:#768390;">// Requires passing the current TextView&#39;s Resources and text size.</span></span>
<span class="line"><span style="color:#768390;">// If the input text is already Spannable,</span></span>
<span class="line"><span style="color:#768390;">// it will return the original object without creating a new SpannableString.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> text </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> PanguText.</span><span style="color:#DCBDFB;">format</span><span style="color:#ADBAC7;">(textView.resources, textView.textSize, </span><span style="color:#96D0FF;">&quot;Xiaoming今年16岁&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Set text.</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.text </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> text</span></span>
<span class="line"><span style="color:#768390;">// Directly format text using whitespace characters for insertion.</span></span>
<span class="line"><span style="color:#768390;">// This method adds extra whitespace characters &quot;&quot; (HSP) to the text.</span></span>
<span class="line"><span style="color:#768390;">// The result below will output the string &quot;Xiaoming今年16岁&quot;.</span></span>
<span class="line"><span style="color:#768390;">// You can also customize the whitespace character at the end of the method.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> text </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> PanguText.</span><span style="color:#DCBDFB;">format</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;Xiaoming今年16岁&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Set text.</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.text </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> text</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>The <code>injectPanguText</code>, <code>injectRealTimePanguText</code>, <code>setTextWithPangu</code>, <code>setHintWithPangu</code>, and <code>PanguText.format</code> methods support the <code>config</code> parameter. You can refer to the <a href="#personalized-configuration">Personalized Configuration</a> section below.</p></div><h4 id="custom-view" tabindex="-1"><a class="header-anchor" href="#custom-view" aria-hidden="true">#</a> Custom View</h4><p><code>PanguText</code> can also be used with custom <code>View</code>. You can extend your <code>View</code> to <code>AppCompatTextView</code> and override the <code>setText</code> method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">MyTextView</span><span style="color:#ADBAC7;">(context: </span><span style="color:#F69D50;">Context</span><span style="color:#ADBAC7;">, attrs: </span><span style="color:#F69D50;">AttributeSet</span><span style="color:#ADBAC7;">? </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">null</span><span style="color:#ADBAC7;">) : </span><span style="color:#F69D50;">AppCompatTextView</span><span style="color:#ADBAC7;">(</span><span style="color:#F69D50;">context</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">attrs</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">setText</span><span style="color:#ADBAC7;">(text: </span><span style="color:#F69D50;">CharSequence</span><span style="color:#ADBAC7;">?, type: </span><span style="color:#F69D50;">BufferType</span><span style="color:#ADBAC7;">?) {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Manually inject here.</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> panguText </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> text?.</span><span style="color:#DCBDFB;">let</span><span style="color:#ADBAC7;"> { PanguText.</span><span style="color:#DCBDFB;">format</span><span style="color:#ADBAC7;">(resources, textSize, it) }</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">super</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">setText</span><span style="color:#ADBAC7;">(panguText, type)</span></span>
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>After injecting <code>PanguText</code> into <code>TextView</code>, if you use <code>android:singleLine=&quot;true&quot;</code> in XML layout or <code>TextView.setSingleLine(true)</code> in code along with <code>android:ellipsize=&quot;...&quot;</code>, this method of setting single-line text may cause unresolvable <code>OBJ</code> characters (truncated by ellipsis) to appear when the text exceeds the screen width, because <code>TextView</code> does not account for <code>Span</code> during measurement, leading to incorrect text width calculation.</p><p>The solution is to use <code>android:maxLines=&quot;1&quot;</code> in XML layout or <code>TextView.setMaxLines(1)</code> in code instead.</p><blockquote><p>The following example</p></blockquote><div class="language-xml line-numbers-mode" data-ext="xml"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">&lt;</span><span style="color:#8DDB8C;">TextView</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:id</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;@+id/text&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:layout_width</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;wrap_content&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:layout_height</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;wrap_content&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:text</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;这是一段很长很长长长长长长长长长长长长还有English混入的的文本&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:maxLines</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;1&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:ellipsize</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;end&quot;</span><span style="color:#ADBAC7;"> /&gt;</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></div><h3 id="personalized-configuration" tabindex="-1"><a class="header-anchor" href="#personalized-configuration" aria-hidden="true">#</a> Personalized Configuration</h3><p><code>PanguText</code> supports personalized configuration. You can use the global static instance <code>PanguText.globalConfig</code> to get the global configuration or configure it individually.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Get global configuration.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> config </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> PanguText.globalConfig</span></span>
<span class="line"><span style="color:#768390;">// Enable or disable the feature.</span></span>
<span class="line"><span style="color:#ADBAC7;">config.isEnabled </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">true</span></span>
<span class="line"><span style="color:#768390;">// Process Spanned text.</span></span>
<span class="line"><span style="color:#768390;">// Processing Spanned text is enabled by default, but this feature is experimental.</span></span>
<span class="line"><span style="color:#768390;">// If issues occur, you can disable it. When disabled, Spanned text will return the original text.</span></span>
<span class="line"><span style="color:#ADBAC7;">config.isProcessedSpanned </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">true</span></span>
<span class="line"><span style="color:#768390;">// Whether to automatically re-measure the text width after processing.</span></span>
<span class="line"><span style="color:#768390;">// Note: After [PanguText] injects text and changes the text,</span></span>
<span class="line"><span style="color:#768390;">// the width of [TextView] will not be calculated automatically.</span></span>
<span class="line"><span style="color:#768390;">// At this time, this feature will call [TextView.setText] to re-execute the measurements,</span></span>
<span class="line"><span style="color:#768390;">// which can fix issues in some dynamic layouts (such as \`RecyclerView\`) where text width changes each time,</span></span>
<span class="line"><span style="color:#768390;">// but may cause performance issues. You can choose to disable this feature.</span></span>
<span class="line"><span style="color:#768390;">// To prevent unnecessary performance overhead,</span></span>
<span class="line"><span style="color:#768390;">// this feature only takes effect on [TextView] with \`maxLines\` set to 1 or \`singleLine\`.</span></span>
<span class="line"><span style="color:#ADBAC7;">config.isAutoRemeasureText </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">true</span></span>
<span class="line"><span style="color:#768390;">// Set patterns to exclude during formatting using regular expressions.</span></span>
<span class="line"><span style="color:#768390;">// For example, exclude all URLs.</span></span>
<span class="line"><span style="color:#ADBAC7;">config.excludePatterns.</span><span style="color:#DCBDFB;">add</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;https?://</span><span style="color:#F47067;">\\\\</span><span style="color:#96D0FF;">S+&quot;</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toRegex</span><span style="color:#ADBAC7;">())</span></span>
<span class="line"><span style="color:#768390;">// For example, exclude emoji placeholders like &quot;[doge]&quot;.</span></span>
<span class="line"><span style="color:#768390;">// If you use [ImageSpan] to display emoji images, you can choose to exclude these placeholders.</span></span>
<span class="line"><span style="color:#ADBAC7;">config.excludePatterns.</span><span style="color:#DCBDFB;">add</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;</span><span style="color:#F47067;">\\\\</span><span style="color:#96D0FF;">[.*?]&quot;</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toRegex</span><span style="color:#ADBAC7;">())</span></span>
<span class="line"><span style="color:#768390;">// Set the spacing ratio for CJK characters.</span></span>
<span class="line"><span style="color:#768390;">// This determines the final layout effect.</span></span>
<span class="line"><span style="color:#768390;">// It is recommended to keep the default ratio and adjust it according to personal preference.</span></span>
<span class="line"><span style="color:#ADBAC7;">config.cjkSpacingRatio </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">7f</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>If you integrated using the <a href="#inject-to-layoutinflater">Inject to LayoutInflater</a> method, configure <code>PanguText.globalConfig</code> before executing <code>PanguTextFactory2.inject(...)</code>, otherwise the configuration will not take effect.</p></div><p>You can also pass the <code>config</code> parameter for personalized configuration when manually injecting or formatting text.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume this is your TextView.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> textView: </span><span style="color:#F69D50;">TextView</span></span>
<span class="line"><span style="color:#768390;">// Create a new configuration.</span></span>
<span class="line"><span style="color:#768390;">// You can set [copyFromGlobal] to false to not copy from the global configuration.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> config </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">PanguTextConfig</span><span style="color:#ADBAC7;">(copyFromGlobal </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">false</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;"> excludePatterns.</span><span style="color:#DCBDFB;">add</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;https?://</span><span style="color:#F47067;">\\\\</span><span style="color:#96D0FF;">S+&quot;</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toRegex</span><span style="color:#ADBAC7;">())</span></span>
<span class="line"><span style="color:#ADBAC7;"> excludePatterns.</span><span style="color:#DCBDFB;">add</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;</span><span style="color:#F47067;">\\\\</span><span style="color:#96D0FF;">[.*?]&quot;</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toRegex</span><span style="color:#ADBAC7;">())</span></span>
<span class="line"><span style="color:#ADBAC7;"> cjkSpacingRatio </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">7f</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#768390;">// You can also copy and create a new configuration from any configuration.</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> config2 </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> config.</span><span style="color:#DCBDFB;">copy</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;"> excludePatterns.</span><span style="color:#DCBDFB;">clear</span><span style="color:#ADBAC7;">()</span></span>
<span class="line"><span style="color:#ADBAC7;"> excludePatterns.</span><span style="color:#DCBDFB;">add</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;https?://</span><span style="color:#F47067;">\\\\</span><span style="color:#96D0FF;">S+&quot;</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toRegex</span><span style="color:#ADBAC7;">())</span></span>
<span class="line"><span style="color:#ADBAC7;"> excludePatterns.</span><span style="color:#DCBDFB;">add</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;</span><span style="color:#F47067;">\\\\</span><span style="color:#96D0FF;">[.*?]&quot;</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toRegex</span><span style="color:#ADBAC7;">())</span></span>
<span class="line"><span style="color:#ADBAC7;"> cjkSpacingRatio </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">7f</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#768390;">// Manually inject and configure.</span></span>
<span class="line"><span style="color:#ADBAC7;">textView.</span><span style="color:#DCBDFB;">injectPanguText</span><span style="color:#ADBAC7;">(config </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> config2)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If you integrated using the <a href="#inject-to-layoutinflater">Inject to LayoutInflater</a> method, you can use the following attributes in the XML layout declaration of <code>TextView</code>, <code>EditText</code>, or their subclasses for personalized configuration.</p><ul><li><code>panguText_enabled</code> corresponds to <code>PanguTextConfig.isEnabled</code></li><li><code>panguText_processedSpanned</code> corresponds to <code>PanguTextConfig.isProcessedSpanned</code></li><li><code>panguText_autoRemeasureText</code> corresponds to <code>PanguTextConfig.isAutoRemeasureText</code></li><li><code>panguText_excludePatterns</code> corresponds to <code>PanguTextConfig.excludePatterns</code>, string array, multiple patterns separated by <code>|@|</code></li><li><code>panguText_cjkSpacingRatio</code> corresponds to <code>PanguTextConfig.cjkSpacingRatio</code></li></ul><blockquote><p>The following example</p></blockquote><div class="language-xml line-numbers-mode" data-ext="xml"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">&lt;</span><span style="color:#8DDB8C;">TextView</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:id</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;@+id/text&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:layout_width</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;wrap_content&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:layout_height</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;wrap_content&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">android:text</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;Xiaoming今年16岁&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">app:panguText_enabled</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;true&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">app:panguText_processedSpanned</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;true&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">app:panguText_autoRemeasureText</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;true&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">app:panguText_excludePatterns</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;https?://\\\\S+;\\\\[.*?]|@|\\\\[.*?]&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">app:panguText_cjkSpacingRatio</span><span style="color:#ADBAC7;">=</span><span style="color:#96D0FF;">&quot;7.0&quot;</span><span style="color:#ADBAC7;"> /&gt;</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>Due to issues with Android Studio, the above attributes may not have auto-completion hints. Please complete them manually.</p><p>Don&#39;t forget to add the declaration <code>xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;</code>.</p></div><p>In custom <code>View</code>, you can extend your <code>View</code> to implement the <code>PanguTextView</code> interface to achieve the same functionality. This feature is also effective for the <a href="#using-the-patching-tool">Using the Patching Tool</a> method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">MyTextView</span><span style="color:#ADBAC7;">(context: </span><span style="color:#F69D50;">Context</span><span style="color:#ADBAC7;">, attrs: </span><span style="color:#F69D50;">AttributeSet</span><span style="color:#ADBAC7;">? </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">null</span><span style="color:#ADBAC7;">) : </span><span style="color:#F69D50;">AppCompatTextView</span><span style="color:#ADBAC7;">(</span><span style="color:#F69D50;">context</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">attrs</span><span style="color:#ADBAC7;">),</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">PanguTextView</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">configurePanguText</span><span style="color:#ADBAC7;">(config: </span><span style="color:#F69D50;">PanguTextConfig</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Configure your [PanguTextConfig].</span></span>
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container warning"><p class="custom-container-title">Notice</p><p>The <code>PanguTextView</code> interface takes precedence over attributes used directly in the XML layout. If you use both methods for configuration, the <code>PanguTextView</code> interface configuration will override the XML layout configuration.</p><p>Individual configurations will override global configurations, and options not configured will follow the global configuration.</p></div>`,48);function v(h,D){const a=t("ExternalLinkIcon");return i(),p("div",null,[r,e("p",null,[s("You can view the KDoc "),e("a",d,[s("click here"),l(a)]),s(".")]),u,e("p",null,[s("If you are using "),e("a",y,[s("ui-component → AppBindingActivity"),l(a)]),s(" in "),A,s(", you need to slightly modify the current code.")]),m])}const B=o(c,[["render",v],["__file","android.html.vue"]]);export{B as default};