package com.hanhai.day_14y; import android.graphics.Color; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.support.v4.widget.TextViewCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.CompoundButton; import android.widget.FrameLayout; import android.widget.RadioButton; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import fragmentkj.QiyuF; import fragmentkj.ShouyeF; public class MainActivity extends AppCompatActivity { private FrameLayout rame; private TextView tv1; private TextView tv2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rame = (FrameLayout) findViewById(R.id.frame); tv1 = (TextView) findViewById(R.id.tv1); tv2 = (TextView) findViewById(R.id.tv2); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.frame, new ShouyeF()); transaction.commit(); tv1.setTextColor(Color.BLACK); tv2.setTextColor(Color.GRAY); tv1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.frame,new ShouyeF()); transaction.commit(); tv1.setTextColor(Color.BLACK); tv2.setTextColor(Color.GRAY); } }); tv2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.frame,new QiyuF()); transaction.commit(); tv1.setTextColor(Color.GRAY); tv2.setTextColor(Color.BLACK); } }); } }
//布局文件 <FrameLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/ll" ></FrameLayout>
帧布局
最新推荐文章于 2022-11-13 15:52:56 发布
本文介绍了一个简单的Android应用程序示例,该应用通过使用Fragment和FragmentTransaction实现了两个页面之间的切换功能,并通过TextView来改变选中状态的颜色反馈。此示例适用于初学者了解Android中页面切换的基本实现方式。
摘要由CSDN通过智能技术生成