0
点赞
收藏
分享

微信扫一扫

不用一句java代码就可以实现指示器tabhost,indicator

IT影子 2022-11-25 阅读 57



原创!绝对原创  - - 

实现原理:

弄3个radioButton 一个radioGroup包起来,然后给drawableButton设置一个selector 选中和未选中的shape就好了.

光说不贴假把式,好了我贴代码了.

<RadioGroup
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:text="热门"

style="@style/style_tab_live"
/>
<RadioButton
style="@style/style_tab_live"
android:text="关注"
/>
<RadioButton
style="@style/style_tab_live"
android:text="最新"
/>


</RadioGroup>


<style name="style_tab_live">
<item name="android:layout_margin">10dp</item>
<item name="android:text">热门</item>
<item name="android:button">@null</item>
<item name="android:textColor">@color/color_tab_selector</item>
<item name="android:gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:drawablePadding">3dp</item>
<item name="android:drawableBottom">@drawable/selector_tab_indicator</item>

</style>



补充资料

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/shape_bg_tab_select"></item>
<item android:state_checked="true" android:drawable="@drawable/shape_bg_tab_select"></item>
<item android:state_pressed="true" android:drawable="@drawable/shape_bg_tab_select"></item>
<item android:drawable="@drawable/shape_bg_tab_no_select"></item>
</selector>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:height="2dp" android:width="50dp" />
<solid android:color="@color/colorBlack"/>
</shape>

没有选中的

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:height="2dp" android:width="50dp"/>
<solid android:color="@color/colorTransparent"/>
</shape>


自定义的videoplayer,不用第三方实现高仿startFragmentForResult ,onFragmentForReuslt的封装

不需要xml包含头部不需要谷歌的action bar纯代码加头部到抽取的baseFragment,baseActivity,更多内容敬请期待!

最后贴上效果图:

不用一句java代码就可以实现指示器tabhost,indicator_ide

使用方法:

RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
View child = group.findViewById(checkedId);
int i = group.indexOfChild(child);
switch (i){
case 0:
break;
case 1:
break;
case 2:
break;
}
//然后做相关操作!
}
});
((RadioButton) radioGroup.getChildAt(0)).setChecked(true);

不需要xml包含头部不需要谷歌的action bar纯代码加头部到抽取的baseFragment,baseActivity



举报

相关推荐

0 条评论