两个selector
一个style
如下selector:
btn_gv_seletor
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@mipmap/home_press" android:state_checked="true"/>
<item android:drawable="@mipmap/home"/>
</selector>
第二个
btn_news_seletor
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@mipmap/newscenter_press" android:state_checked="true"/>
<item android:drawable="@mipmap/newscenter"/>
</selector>
第三个
btn_text_seletor
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#f00" android:state_checked="true" />
<item android:color="#fff"/>
</selector>
主页面
<RadioGroup
android:id="@+id/rg_rb"
android:background="@mipmap/bottom_tab_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_home"
style="@style/BottpmTabStyle"
android:drawableTop="@drawable/btn_home_selector"
android:text="首页"
/>
<RadioButton
android:id="@+id/rb_news"
style="@style/BottpmTabStyle"
android:drawableTop="@drawable/btn_news_selector"
android:text="新闻"
/>
<RadioButton
android:id="@+id/rb_smart"
style="@style/BottpmTabStyle"
android:drawableTop="@drawable/btn_smart_selector"
android:text="智慧"
/>
</RadioGroup>
样式:
在style文件下
<!-- Base application theme. -->
<style name="BottpmTabStyle" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">5dp</item>
<item name="android:button">@null</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:drawablePadding">3dp</item>
<item name="android:textColor">@drawable/btn_text_selector</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
</style>
contentFragment
public class ContentFragment extends BaseFragment {
@ViewInject(R.id.rg_rb)
private RadioGroup radioGroup;
@Override
public View initViews() {
View view = View.inflate(mActivity,R.layout.fragment_content,null);
// radioGroup = (RadioGroup) view.findViewById(R.id.rg_rb);
return view;
}
@Override
public void initData() {
radioGroup.check(R.id.rb_home);//默认勾选首页
}
}
传承者(Inheritors)欢迎各位纠正错误,评论,吐槽!!!