一:建立一个activity_header.xml 代码如下
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TopBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" >
<Button
android:id="@+id/BackBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@drawable/back" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:paddingTop="6dp"
android:text=""
android:textSize="25sp" />
</RelativeLayout>
二:在需要包含activity_header.xml 的xml文件加上
<include layout="@layout/activity_head"/>
三:在java代码里设置TextView里面的text
TextView text=(TextView)findViewById(R.id.text);
// text.setText("充值");
String str=getResources().getString(R.string.depositInfo); //在strings.xml里面有<string name="depositInfo">充值</string>
text.setText(str);