xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ddgl.DdglActivity">
<LinearLayout
android:layout_width="@dimen/dp_50"
android:id="@+id/fh"
android:layout_height="@dimen/dp_50">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_15"
android:layout_marginLeft="@dimen/dp_15"
android:src="@mipmap/path" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/sp_21"
android:textColor="#3b3b3b"
android:text="历史订单"
android:textStyle="bold"
android:layout_marginLeft="@dimen/dp_20"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="15dp"
android:id="@+id/group"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/qb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:text="全部"
android:textStyle="bold"
android:textColor="#3b3b3b"
android:textSize="@dimen/sp_17"
android:drawableBottom="@drawable/button_item"
android:listSelector="@android:color/transparent"
/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/fwz"
android:gravity="center"
android:button="@null"
android:textSize="@dimen/sp_16"
android:textColor="#bac0cc"
android:text="服务中"
android:drawableBottom="@drawable/button_item"
android:listSelector="@android:color/transparent"
/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableBottom="@drawable/button_item"
android:id="@+id/ywc"
android:gravity="center"
android:button="@null"
android:text="已完成"
android:textSize="@dimen/sp_16"
android:textColor="#bac0cc"
android:listSelector="@android:color/transparent"
/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableBottom="@drawable/button_item"
android:id="@+id/yqx"
android:gravity="center"
android:button="@null"
android:text="已取消"
android:textSize="@dimen/sp_16"
android:textColor="#bac0cc"
android:listSelector="@android:color/transparent"
/>
</RadioGroup>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ebebeb"
android:layout_marginTop="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
/>
<LinearLayout
android:id="@+id/bj"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
</LinearLayout>
</LinearLayout>
_____________________________________________________________________________________________________
Activity
package com.sf.fczp.ddgl;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import com.sf.fczp.R;
public class DdglActivity extends AppCompatActivity {
RadioButton qb, fwz, yqx, ywc;
LinearLayout line,fh;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ddgl);
qb = findViewById(R.id.qb);
fwz = findViewById(R.id.fwz);
yqx = findViewById(R.id.yqx);
ywc = findViewById(R.id.ywc);
line = findViewById(R.id.bj);
fh = findViewById(R.id.fh);
//默认显示全部
quanbu();
onclic();
}
public void onclic(){
fh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//全部点击事件
qb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quanbu();
}
});
//服务中点击事件
fwz.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fuwuzhong();
}
});
//已取消点击事件
yqx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
yiquxiao();
}
});
//已完成点击事件
ywc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
yiwancheng();
}
});
}
public void quanbu() {
getSupportFragmentManager().beginTransaction().replace(R.id.bj, new QuanBuFragment()).commit();
Drawable drawable = getResources().getDrawable(R.drawable.button_item);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
qb.setCompoundDrawables(null, null, null, drawable);
//隐藏Drawables
//qb.setCompoundDrawables(null,null,null,null);
//点击改变字体颜色
qb.setTextColor(ContextCompat.getColor(this, R.color.color_3b3b3b));
//点击加粗
qb.getPaint().setFakeBoldText(true);
fwz.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
fwz.getPaint().setFakeBoldText(false);
yqx.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
yqx.getPaint().setFakeBoldText(false);
ywc.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
ywc.getPaint().setFakeBoldText(false);
fwz.setCompoundDrawables(null, null, null, null);
yqx.setCompoundDrawables(null, null, null, null);
ywc.setCompoundDrawables(null, null, null, null);
}
public void fuwuzhong(){
getSupportFragmentManager().beginTransaction().replace(R.id.bj, new FuWuZhongFragment()).commit();
Drawable drawable = getResources().getDrawable(R.drawable.button_item);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
fwz.setCompoundDrawables(null, null, null, drawable);
//隐藏Drawables
//qb.setCompoundDrawables(null,null,null,null);
fwz.setTextColor(ContextCompat.getColor(this, R.color.color_3b3b3b));
fwz.getPaint().setFakeBoldText(true);
qb.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
qb.getPaint().setFakeBoldText(false);
yqx.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
yqx.getPaint().setFakeBoldText(false);
ywc.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
ywc.getPaint().setFakeBoldText(false);
qb.setCompoundDrawables(null, null, null, null);
yqx.setCompoundDrawables(null, null, null, null);
ywc.setCompoundDrawables(null, null, null, null);
}
public void yiquxiao(){
getSupportFragmentManager().beginTransaction().replace(R.id.bj, new YiQuXiaoFragment()).commit();
Drawable drawable = getResources().getDrawable(R.drawable.button_item);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
yqx.setCompoundDrawables(null, null, null, drawable);
//隐藏Drawables
//qb.setCompoundDrawables(null,null,null,null);
yqx.setTextColor(ContextCompat.getColor(this, R.color.color_3b3b3b));
yqx.getPaint().setFakeBoldText(true);
fwz.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
fwz.getPaint().setFakeBoldText(false);
qb.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
qb.getPaint().setFakeBoldText(false);
ywc.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
ywc.getPaint().setFakeBoldText(false);
fwz.setCompoundDrawables(null, null, null, null);
qb.setCompoundDrawables(null, null, null, null);
ywc.setCompoundDrawables(null, null, null, null);
}
public void yiwancheng(){
getSupportFragmentManager().beginTransaction().replace(R.id.bj, new YiWanChengFragment()).commit();
Drawable drawable = getResources().getDrawable(R.drawable.button_item);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
ywc.setCompoundDrawables(null, null, null, drawable);
//隐藏Drawables
//qb.setCompoundDrawables(null,null,null,null);
ywc.setTextColor(ContextCompat.getColor(this, R.color.color_3b3b3b));
ywc.getPaint().setFakeBoldText(true);
yqx.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
yqx.getPaint().setFakeBoldText(false);
fwz.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
fwz.getPaint().setFakeBoldText(false);
qb.setTextColor(ContextCompat.getColor(this, R.color.color_bac0cc));
qb.getPaint().setFakeBoldText(false);
fwz.setCompoundDrawables(null, null, null, null);
yqx.setCompoundDrawables(null, null, null, null);
qb.setCompoundDrawables(null, null, null, null);
}
}
_____________________________________________________________________________________________________
Fragment
public class QuanBuFragment extends Fragment {
Activity activity;
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
activity = getActivity();
View view = inflater.inflate(R.layout.qb, container, false);
return view;
}
}
——————————————————————————————————————————————————————————————————————————————
button_item.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#015aff"/>
<size android:height="2dp" android:width="45dp"/>
</shape>