android - 包括布局 android - 导致按钮背景颜色出现问题

标签 android android-layout android-fragments android-button

我有 1 个布局,这在我项目的所有 3 个选项卡( fragment )中都很常见。所以我所做的是为该公共(public)结构创建单独的布局,并将该布局包含在所有 fragment 布局中。布局基本上有 4 个按钮,单击这些按钮后,我将更改按钮的背景颜色并相应地显示数据。

This is the 1st tab in which its coming perfect.

This is the second tab where all the buttons are getting the blue color.

代码:-

@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/

相关文章:

android - 所选 View 的默认选择器

android - 使用 Fragment 对话框在暗模式和亮模式之间切换时,如何安全地重新创建我的 Activity?

android - 非矩形 TextView

android - 退出动画不起作用; FragmentTransaction 自定义动画不适用于隐藏

android - 我应该如何在 android 上保存包含 ListView 的 fragment 状态?

android - 我们如何在android中创建多点触控?

javascript - HTML5 Canvas : Prevent moving on phone

android - 从 Firebase DB 中检索失败的值,得到 null 而不是预期的 String

android - BOOT_COMPLETED 无法正常工作

android:背景图像从不可见到可见时第一次不显示