完成了底部导航栏,通过include控件进行包裹一个页面,对于每个按钮设置点击和未点击的事件
public void setselector(){
iv_home.setSelected(false);
iv_community.setSelected(false);
iv_self.setSelected(false);
tv_home.setTextColor(ContextCompat.getColor(this, R.color.gray));
tv_community.setTextColor(ContextCompat.getColor(this, R.color.gray));
tv_self.setTextColor(ContextCompat.getColor(this, R.color.gray));
}
iv_home.setSelected(false);
iv_community.setSelected(false);
iv_self.setSelected(false);
tv_home.setTextColor(ContextCompat.getColor(this, R.color.gray));
tv_community.setTextColor(ContextCompat.getColor(this, R.color.gray));
tv_self.setTextColor(ContextCompat.getColor(this, R.color.gray));
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/baseline_question_answer_24"/>
<item android:state_selected="false" android:drawable="@drawable/baseline_question_answer_unpress"/>
</selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/baseline_question_answer_24"/>
<item android:state_selected="false" android:drawable="@drawable/baseline_question_answer_unpress"/>
</selector>