0

1 つの共有設定があり、1 つの段落がそこに格納されています。値は共有設定に適切に書き込まれており、それから読み取ることができ、webview に表示されます。これでエラーはありません。

XMLファイルでsting宣言を使用し、正当化モードで整列させたところ、正常にデータが表示されました。

私の質問は、文字列を動的に使用しているときに、Justify モードで上記のテキストを webview に揃える方法です。

質問への説明

ユーザーから 1 段落のデータを取得している、または string.xml ファイルにないアクティビティで大きなデータを文字列に割り当てているとします。

以下のコードは、string.xml ファイルから正当化モードでデータを正常に表示したことを示しています。

public class MainActivity extends Activity {
    SharedPreferences pref;
    SharedPreferences.Editor edi;
    String prefname="Test";
    static final  String Id ="Desc";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

             String s=getResources().getString(com.testwebviewalign.R.string.MyDesc);


       //writing to shared 
        pref=getSharedPreferences(prefname, MODE_PRIVATE);
        edi=pref.edit();
        edi.putString(Id,s );
        edi.commit();

        //reading from shared
        pref=getSharedPreferences(new MainActivity().prefname, MODE_PRIVATE);
        String D=pref.getString(new MainActivity().Id, null);


        WebView wv=(WebView)findViewById(com.testwebviewalign.R.id.webView1);
        //wv.setVerticalScrollBarEnabled(true);
        wv.loadData(D, "text/html", "utf-8");


    }

  }

文字列宣言用XMLファイル

    <string name="MyDesc">
       <![CDATA[
        <html>
             <body style="text-align:justify;color:black">
This valuse is for testing the alignment of the android file when using the webview, Actual thing is to convert the local text view activity in to the webview so that we can align text in justify mode. Justify mode that we can align with two sides porerly and text will display in a decen manner and well aligned format. Only with webview its posiible in native android activity. Thak you
            </body>
        </html>
       ]]>

    </string>

私が必要とするのは、次のようなコードで宣言および初期化されていると仮定して、xmlファイルから読み取っていないときに、整列モードでデータを表示する方法です。

public class MainActivity extends Activity {
    SharedPreferences pref;
    SharedPreferences.Editor edi;
    String prefname="Test";
    static final  String Id ="Desc";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

             String s="This valuse is for testing the alignment of the android file when using the webview, Actual thing is need to convert the local text view activity in to the webview so that we can align text in justify mode. Justify mode is sthat we can align with two sides porerly and text will display in a decen manner and well aligned format. ONly with webview its posiible in native android activity. Thak you";



       //writing to shared 
        pref=getSharedPreferences(prefname, MODE_PRIVATE);
        edi=pref.edit();
        edi.putString(Id,s );
        edi.commit();

        //reading from shared
        pref=getSharedPreferences(new MainActivity().prefname, MODE_PRIVATE);
        String D=pref.getString(new MainActivity().Id, null);


        WebView wv=(WebView)findViewById(com.testwebviewalign.R.id.webView1);
        //wv.setVerticalScrollBarEnabled(true);
        wv.loadData(D, "text/html", "utf-8");


    }

  }

助けてください、あなたの助けに感謝します;

4

1 に答える 1

0

私はこれに対する解決策を自分で見つけたので、次のコードを使用しました。これでウェブビューの表示文字列を変更するだけです

wv.loadData("<html><body style=text-align:justify;color:black>"+D+"</body></html>", "text/html", "utf-8");

HTMLタグを直接追加して、Webビューのテキストのスタイルを設定できます。みんなありがとう。

于 2012-11-12T12:23:50.533 に答える