您的位置:首页 > 其它

萝卜

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: