指定fragment跳转

 
 
wddfk .setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
//跳转到另一个fragment的Activity
Intent intent = new Intent(getActivity(), Merchandise_spdd. class );
//传一个值,如果有多个,传的时候名一样,之不一样,另一个Activity判断一个名字就好了
intent.putExtra( "from" , "daifukuan" );
startActivity(intent);
}
});

//另一个Activity里
//接受上一个类传过来的名字
Intent intent=getIntent();
String from=intent.getExtras().getString( "from" );
//判断这个名字是否和上一个页面的值是一对,如果是就显示这个fragment
if (from.equals( "yiwancheng" )){
getSupportFragmentManager().beginTransaction().replace(R.id. bj , new Fragment_ywc()).commit();
//自己画的线
Drawable drawable= getResources().getDrawable(R.drawable. button_item );
// 这一步必须要做,否则不会显示.
drawable.setBounds( 0 , 0 , drawable.getMinimumWidth(), drawable.getMinimumHeight());
//设置线的位置 左上右下 ywc .setCompoundDrawables( null , null , null ,drawable);
//字的颜色 ywc .setTextColor(getResources().getColor(R.color. red ));
//隐藏Drawables
//qb.setCompoundDrawables(null,null,null,null);
//把其他的都设置成空 qb .setCompoundDrawables( null , null , null , null );
dsh .setCompoundDrawables( null , null , null , null );
dfk .setCompoundDrawables( null , null , null , null );
dcl .setCompoundDrawables( null , null , null , null );
qb .setTextColor(getResources().getColor(R.color. black ));
dsh .setTextColor(getResources().getColor(R.color. black ));
dfk .setTextColor(getResources().getColor(R.color. black ));
dcl .setTextColor(getResources().getColor(R.color. black ));
}
//自己画的线
< shape
xmlns: android = "http://schemas.android.com/apk/res/android"
android :shape= "rectangle" >
< solid android :color= "#ff0000" />
< size android :height= "2dp" android :width= "40dp" />
</ shape >

猜你喜欢

转载自blog.csdn.net/qq_40983361/article/details/80984937
今日推荐