求教大神,我在MainActivity上面做个了一个FragmentTabhost,在第一个碎片的顶部加了两个按钮,然后点击事件如下,本来我想让它们能在点击的时候能更换按钮的背景和按钮上字体的颜色,但是,现在好像不起作用,求大神帮我看看怎么回事
package com.ruicaiedu.ifriend.fragment;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.ruicaiedu.ifriend.R;
/**
-
Created by Administrator on 2016/7/18 0018.
*/
public class FragmentFirstNearby extends Fragment {
private View view;private Button btn_firstfragment_nearbyMan;
private Button btn_firstfragment_nearbyQun;@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_first, container, false);
btn_firstfragment_nearbyMan = (Button) view.findViewById(R.id.btn_firstfragment_nearbyMan);
btn_firstfragment_nearbyQun = (Button) view.findViewById(R.id.btn_firstfragment_nearbyQun);//设置两个按钮的监听事件 btn_firstfragment_nearbyMan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {//按的左边的附近的人 的按钮 //设置两个按钮的颜色 btn_firstfragment_nearbyMan.setBackground(getResources().getDrawable(R.drawable.firsttopleftwhite)); btn_firstfragment_nearbyMan.setTextColor(getResources().getColor(R.color.themeColor)); btn_firstfragment_nearbyQun.setBackground(getResources().getDrawable(R.drawable.firsttoprigthpurple)); btn_firstfragment_nearbyQun.setTextColor(getResources().getColor(R.color.viewtheme)); } }); btn_firstfragment_nearbyMan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {//按的 右边的附近的群的 按钮 //设置两个按钮的颜色 btn_firstfragment_nearbyQun.setBackground(getResources().getDrawable(R.drawable.firsttoprightwhite)); btn_firstfragment_nearbyQun.setTextColor(getResources().getColor(R.color.themeColor)); btn_firstfragment_nearbyMan.setBackground(getResources().getDrawable(R.drawable.firsttopleftpurple)); btn_firstfragment_nearbyMan.setTextColor(getResources().getColor(R.color.viewtheme)); } }); return view;
}
}