我有 1 个布局,这在我项目的所有 3 个选项卡( fragment )中都很常见。所以我所做的是为该公共(public)结构创建单独的布局,并将该布局包含在所有 fragment 布局中。布局基本上有 4 个按钮,单击这些按钮后,我将更改按钮的背景颜色并相应地显示数据。
代码:-
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container, final Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment,
container, false);
mLvIncomingCalls = (ListView) rootView.findViewById(R.id.lv);
mBtnDay = (Button) rootView.findViewById(R.id.btnDay);
mBtnWeek = (Button) rootView.findViewById(R.id.btnWeek);
mBtnMonth = (Button) rootView.findViewById(R.id.btnMonth);
mBtnAllTime = (Button) rootView.findViewById(R.id.btnAllTime);
mBtnDay.setOnClickListener(btnDayClickListener);
mBtnWeek.setOnClickListener(btnWeekClickListener);
mBtnMonth.setOnClickListener(btnMonthClickListener);
mBtnAllTime.setOnClickListener(btnAllTimeClickListener);
mBtnDay.setBackgroundColor(getResources().getColor(
android.R.color.holo_blue_light));
return rootView;
}
现在如快照所示,问题是默认情况下在第二个选项卡中所有按钮都变成蓝色。我不明白为什么所有按钮都变成蓝色,因为在我添加上面代码的所有 fragment 中,默认情况下 Day 按钮的颜色仅变为蓝色。
我需要为所有人创建单独的布局吗?
任何人对此有任何想法,请指导我。
最佳答案
在 onCreateView
中,您可以将其他按钮颜色设置为灰色。这样绝对不应该发生。它发生的原因是个谜,我相信系统以某种方式错误地回收了 Drawable
。
关于android - 包括布局 android - 导致按钮背景颜色出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22753655/