package com.example.myapplication; import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; import fragments.Sy; import fragments.Wd; import fragments.Wtt; import fragments.Xg; public class MainActivity extends AppCompatActivity { private TextView shouye; private TextView xigua; private TextView wtt; private TextView wode; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //查找控件 shouye = (TextView) findViewById(R.id.shouye); xigua = (TextView) findViewById(R.id.xigua); wtt = (TextView) findViewById(R.id.wtt); wode = (TextView) findViewById(R.id.wode); //展示第一个视图 FragmentManager manager=getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.fl,new Sy()); transaction.commit(); shouye.setTextColor(Color.RED); xigua.setTextColor(Color.GRAY); wtt.setTextColor(Color.GRAY); wode.setTextColor(Color.GRAY); //点击事件 shouye.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager manager=getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.fl,new Sy()); transaction.commit(); shouye.setTextColor(Color.RED); xigua.setTextColor(Color.GRAY); wtt.setTextColor(Color.GRAY); wode.setTextColor(Color.GRAY); } }); xigua.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager manager=getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.fl,new Xg()); transaction.commit(); shouye.setTextColor(Color.GRAY); xigua.setTextColor(Color.RED); wtt.setTextColor(Color.GRAY); wode.setTextColor(Color.GRAY); } }); wtt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager manager=getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.fl,new Wtt()); transaction.commit(); shouye.setTextColor(Color.GRAY); xigua.setTextColor(Color.GRAY); wtt.setTextColor(Color.RED); wode.setTextColor(Color.GRAY); } }); wode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager manager=getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.fl,new Wd()); transaction.commit(); shouye.setTextColor(Color.GRAY); xigua.setTextColor(Color.GRAY); wtt.setTextColor(Color.GRAY); wode.setTextColor(Color.RED); } }); } }
//布局<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/ll" android:id="@+id/fl"> </FrameLayout>
帧布局
最新推荐文章于 2023-03-20 23:02:08 发布