萝卜
2017-10-22 20:27
148 查看
package com.luobo.www.luoboman; import android.content.Intent; import android.graphics.Color; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ FragmentManager fm; FragmentTransaction transaction; Fragment_Home fragment_home; Fragment_class fragment_class; Fragment_cart fragment_cart; Fragment_user fragment_user; RadioGroup radioGroup; RadioButton nav_home,nav_class,nav_cart,nav_mine; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initview(); initdata(); } public void initview(){ fragment_home = new Fragment_Home(); fragment_class = new Fragment_class(); fragment_cart = new Fragment_cart(); fragment_user = new Fragment_user(); nav_home = (RadioButton) findViewById(R.id.nav_home); nav_class = (RadioButton) findViewById(R.id.nav_class); nav_cart = (RadioButton) findViewById(R.id.nav_cart); nav_mine = (RadioButton) findViewById(R.id.nav_mine); radioGroup = (RadioGroup) findViewById(R.id.nav_radioGroup); } public void initdata(){ nav_home.setChecked(true); FragmentManager fm1 = getSupportFragmentManager(); FragmentTransaction ftransaction = fm1.beginTransaction(); ftransaction.replace(R.id.layout,fragment_home); ftransaction.commit(); nav_home.setTextColor(Color.RED); nav_class.setTextColor(Color.BLACK); nav_cart.setTextColor(Color.BLACK); nav_mine.setTextColor(Color.BLACK); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { fm = getSupportFragmentManager(); transaction = fm.beginTransaction(); switch (i) { case R.id.nav_home: transaction.replace(R.id.layout,fragment_home); nav_home.setTextColor(Color.RED); nav_class.setTextColor(Color.BLACK); nav_cart.setTextColor(Color.BLACK); nav_mine.setTextColor(Color.BLACK); break; case R.id.nav_class: transaction.replace(R.id.layout,fragment_class); nav_home.setTextColor(Color.BLACK); nav_class.setTextColor(Color.RED); nav_cart.setTextColor(Color.BLACK); nav_mine.setTextColor(Color.BLACK); break; case R.id.nav_cart: transaction.replace(R.id.layout,fragment_cart); nav_home.setTextColor(Color.BLACK); nav_class.setTextColor(Color.BLACK); nav_cart.setTextColor(Color.RED); nav_mine.setTextColor(Color.BLACK); break; case R.id.nav_mine: transaction.replace(R.id.layout,fragment_user); nav_home.setTextColor(Color.BLACK); nav_class.setTextColor(Color.BLACK); nav_cart.setTextColor(Color.BLACK); nav_mine.setTextColor(Color.RED); break; } transaction.commit(); } }); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.nav_top_zxing: Toast.makeText(MainActivity.this,"扫描二维码",Toast.LENGTH_SHORT).show(); Intent intent_zxing = new Intent(MainActivity.this,ZxingActivity.class); startActivity(intent_zxing); break; case R.id.nav_top_talk: Toast.makeText(MainActivity.this,"消息",Toast.LENGTH_SHORT).show(); Intent intent_talk=new Intent(MainActivity.this,TalkActivity.class); startActivity(intent_talk); break; } }}
package com.luobo.www.luoboman;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by 杨文倩 on 2017/10/11.
*/
public class Fragment_cart extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.item_cart,null);
return view;
}
}
相关文章推荐
- 冬季多食用萝卜可加速消化养胃暖身(图)
- 吃萝卜去口气(口臭)
- 心态的力量(开水改变鸡蛋、咖啡粉、萝卜状态)
- 保卫萝卜秘籍
- 新浪2014校招的两道笔试题. [搬萝卜 & 取水果]
- Menu的自己定义实现-------保卫萝卜造塔升级塔菜单实现
- 新萝卜家园Ghost版Win10系统X32极速装机版2015年4月
- 选择中医 - 虚寒性体质的人吃什么好(萝卜、生姜、地瓜、大蒜)
- 保卫萝卜游戏分析
- 萝卜家园 Ghost XP 新春装机版 V200801
- 吃萝卜去口气(口臭)
- 这年头连萝卜都靠不住了
- 绿色系统收藏分享:萝卜家园系统下载
- 萝卜白菜的小站
- 深度剖析萝卜教育网商业模式那点事
- 深度技术 + 雨林木风 + 电脑公司 + 萝卜家园 ...
- 选择中医 - 虚寒性体质的人吃什么好(萝卜、生姜、地瓜、大蒜)
- openSession出错:蓝萝卜blu Hibernate4中使用getCurrentSession报Could not obtain transaction-synchronized Sessio
- 橘子与萝卜同食容易导致甲状腺肿(图)
- 吃萝卜去口气(口臭)[转]