底部按钮 字体变颜色+焦点事件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context="com.example.zhangt.fragmenttwo.MainActivity">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <RadioGroup
            android:id="@+id/rg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true">
            <RadioButton
                android:id="@+id/rb_1"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="首页"
                android:button="@null"
                android:checked="true"
               />
            <RadioButton
                android:id="@+id/rb_2"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="分类"
                android:button="@null"
               />
            <RadioButton
                android:id="@+id/rb_3"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="发现"
                android:button="@null"
            />
            <RadioButton
                android:id="@+id/rb_4"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="购物车"
                android:button="@null"
          />
            <RadioButton
                android:id="@+id/rb_5"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="我的"
                android:button="@null"
              />
        </RadioGroup>
        <FrameLayout
            android:id="@+id/frag"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/rg"></FrameLayout>
    </RelativeLayout>


</RelativeLayout>
//
添加 Fragment 
package com.example.zhangt.fragmenttwo;

import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;

import com.example.zhangt.fragmenttwo.Fragement.Five;
import com.example.zhangt.fragmenttwo.Fragement.Four;
import com.example.zhangt.fragmenttwo.Fragement.One;
import com.example.zhangt.fragmenttwo.Fragement.Three;
import com.example.zhangt.fragmenttwo.Fragement.Two;

public class MainActivity extends AppCompatActivity {

    private RadioGroup ra;

    @Override
    // Framnent  里套Fragment     Viewpager+Fragment 联动
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ra = (RadioGroup) findViewById(R.id.rg);
        ra.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId){
                    case R.id.rb_1:
                        addfragment(new One());
                        break;
                    case R.id.rb_2:
                        addfragment(new Two());
                        break;
                    case R.id.rb_3:
                        addfragment(new Three());
                        break;
                    case R.id.rb_4:
                        addfragment(new Four());
                        break;
                    case R.id.rb_5:
                        addfragment(new Five());
                        break;
                    default:
                        break;
                }
            }
        });
    }
    public void addfragment(Fragment f){
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frag,f).commit();
    }

}
 
 
///
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="@color/green"></item>
    <item android:state_checked="true" android:color="@color/green"></item>
    <item android:state_pressed="true" android:color="@color/green"></item>
    <item android:color="@color/black"/>
</selector>
 
 
<RadioButton
    android:clickable="true"
    android:id="@+id/rb_5"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
 ///   android:textColor="@drawable/text_selector"
    android:text="我的"
    android:button="@null"
    />
 
 
 
 
 
 
 
 
 
 
 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值