<RelativeLayout
xmlns:android=“http://schemas.android.com/apk/res/android”
android:id="@+id/rl_content"
android:layout_width=“match_parent”
android:layout_height=“match_parent”>
<TextView
android:id="@+id/tv_show"
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_centerInParent=“true”
android:gravity=“center”
android:text=“TEXT”
android:textColor="@color/light_blue_2e"
android:textSize=“30sp”/>
1.1.2、总结
1.2、所属的Fragment向Activity传值
1.2.1、代码实例
Test6FragmentActivity
public class Test6FragmentActivity extends AppCompatActivity implements ResourceFragment.MyListener {
private TextView tvShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test6_fragment);
tvShow = findViewById(R.id.tv_show);
}
@Override
public void sendMessage(String msg) {
if (!TextUtils.isEmpty(msg)){
tvShow.setText(msg);
}
}
}
布局文件:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout
xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".fragment.test6.Test6FragmentActivity">
<TextView
android:id="@+id/tv_show"
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Text”
android:layout_centerHorizontal=“true”
android:textSize=“24sp”
android:gravity=“center”
android:textColor="@color/light_blue_2e"
android:layout_margin=“10dp”
/>
<fragment
android:id="@+id/fragment_resource"
android:name=“com.gs.common3.fragment.test6.ResourceFragment”
android:layout_width=“match_parent”
android:layout_height=“300dp”
android:layout_below="@id/tv_show"
android:layout_marginTop=“20dp”/>
Reso