Android中的動態字符串的處理
阿新 • • 發佈:2018-05-12
and gets xmlns XA 字符 RR odin RM androi
1.效果顯示
2. MainAcitivity.java
1 package com.example.app2; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.widget.TextView; 6 7 public class MainActivity extends AppCompatActivity { 8 private TextView textView; 9 @Override 10 protectedvoid onCreate(Bundle savedInstanceState) { 11 super.onCreate(savedInstanceState); 12 setContentView(R.layout.activity_main); 13 textView = (TextView) findViewById(R.id.tv); 14 String temp = this.getString(R.string.hello); 15 String result = String.format(temp,"SASS","Android");16 textView.setText(result); 17 } 18 }
2.activity_main.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin" 10 tools:context="com.example.app2.MainActivity" 11 android:orientation="vertical"> 12 13 <TextView 14 android:id="@+id/tv" 15 android:layout_width="wrap_content" 16 android:layout_height="wrap_content" 17 /> 18 19 </LinearLayout>
Android中的動態字符串的處理