小编gor*_*ga1的帖子

BottomNavigationView 文本在更改时闪烁

这里闪烁:http : //gph.is/2GH9P0b

<android.support.design.widget.BottomNavigationView
       android:id="@+id/navigation"
       style="@style/BottomNavigation"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:layout_marginEnd="0dp"
       android:layout_marginStart="0dp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:menu="@menu/navigation" />
Run Code Online (Sandbox Code Playgroud)

样式文件

<style name="BottomNavigation">
    <item name="android:background">@color/colorPrimary</item>
    <item name="itemIconTint">@drawable/nav_bottom_selector</item>
    <item name="itemTextColor">@drawable/nav_bottom_text_selector</item>
</style>
Run Code Online (Sandbox Code Playgroud)

选择器nav_bottom_text_selectornav_bottom_selector具有相同的代码。

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@android:color/white" android:state_checked="true"/>
    <item android:color="#6e6e6e" />
Run Code Online (Sandbox Code Playgroud)

MainActivity.class 这是选项卡更改侦听器。但我认为问题不在这里,因为即使我评论这部分,它也一直在闪烁。

navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected (@NonNull MenuItem item) {

        switch (item.getItemId()) {
            case R.id.navigation_exercises:
                // even not replace tabs, just hide and show                          
                fragmentManager.beginTransaction().show(exerciseFragment).hide(workoutFragment).hide(profileFragment).commit();
                SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_EXERCISE);
                break;
            case R.id.navigation_workouts:
                fragmentManager.beginTransaction().hide(exerciseFragment).show(workoutFragment).hide(profileFragment).commit();
                SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_WORKOUTS);
                break;

            case R.id.navigation_profile:
                fragmentManager.beginTransaction().hide(exerciseFragment).hide(workoutFragment).show(profileFragment).commit(); …
Run Code Online (Sandbox Code Playgroud)

xml android selector drawable android-bottom-nav-view

8
推荐指数
1
解决办法
1733
查看次数

在 RecyclerView 中未正确解析暗模式颜色

我正在尝试实现夜间模式,但我遇到了问题:CardView不会将颜色更改为night值,但活动正确地将其背景更改为夜间颜色值。

请帮助理解这个问题。

MainActivity

public class NewFinishActivity extends AppCompatActivity {

    @BindView(R.id.finishRecycler)
    RecyclerView finishRecycler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

        setContentView(R.layout.activity_new_finish);
        ButterKnife.bind(this);


        LevelRecyclerAdapter mAdapter = new LevelRecyclerAdapter(getApplicationContext(), new ArrayList<>());
        finishRecycler.setAdapter(mAdapter);
    }
}
Run Code Online (Sandbox Code Playgroud)

MainActivity 布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    android:background="@color/background_color"
    tools:context=".activities.NewFinishActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/finishRecycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background_color"
        android:orientation="vertical"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

适配器

public class LevelRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<UserLevel> mItems;
    private Context mContext;

    public LevelRecyclerAdapter(Context context, List<UserLevel> items) {
        mContext = context; …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-view android-recyclerview android-darkmode

4
推荐指数
1
解决办法
1141
查看次数