Цвет панели инструментов Android становится синим, когда вы видите фрагмент - PullRequest
0 голосов
/ 25 июня 2019

У меня есть приложение, которое работает без проблем. В этом приложении я отображаю продукты с сервера. Когда вы нажимаете на один из продуктов, мы вводим операцию сведений, чтобы показать подробности. Все работает нормально. Но когда я идуна это действие с одной из других страниц программы, которая является фрагментом (операция с вкладкой и просмотром пейджера и фрагментов). Цвет панели инструментов и белый вид изображения изменяются на синий

enter image description here

enter image description here

помогите пожалуйста

это мой фрагмент кода:

public class CatFragment extends Fragment {
    View view;
    String cat;
    RecyclerView recyclerView;
    CatViewModel viewModel=new CatViewModel();
    CompositeDisposable compositeDisposable=new CompositeDisposable();
    public static CatFragment newInstance(String title) {
        Bundle args = new Bundle();
        args.putString("title",title);
        CatFragment fragment = new CatFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.cat_fragment, container, false);
        }

        setupViews();
        viewModel.getTabItem(cat)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SingleObserver<List<Product>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                        compositeDisposable.add(d);
                    }

                    @Override
                    public void onSuccess(List<Product> products) {
                        recyclerView.setAdapter(new CatAdapter(products, new CatAdapter.OnItemClickListener() {
                            @Override
                            public void onItemClick(String id) {
                                Intent intent=new Intent(getActivity(), DetailActivity.class);
                                intent.putExtra("id",id);
                                startActivity(intent);
                            }
                        }));
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.i("LOG", "onError: "+e.toString());
                    }
                });
        return view;
    }



    private void setupViews() {
        cat=getArguments().getString("title");
        recyclerView=view.findViewById(R.id.rv_catFragment_catItem);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        Log.i("LOG",cat);
    }

    @Override
    public void onDestroy() {
        compositeDisposable.clear();
        super.onDestroy();
    }


}

подробные коды активности:

public class DetailActivity extends AppCompatActivity {
    DetailViewModel detailViewModel = new DetailViewModel();
    CompositeDisposable compositeDisposable = new CompositeDisposable();
    String id,title;
    TextView txtTitle, txtName, txtColor, txtguarantee, txtPrice, txtPoints, txtMore, txtDescription;
    ImageView imgImage, imgShare, imgFav, imgCart, imgMore, imgBack;
    RecyclerView recyclerView;
    CardView properties;
    CardView comments;
    RatingBar ratingBar;
    Button btnAddToBasket;
    List<RatingModel> ratingModels;
    NestedScrollView nestedScrollView;
    Thread thread;
    RelativeLayout toolbar;
    int toolbarMergeColor, drawableMergeColor;
    TextView txtToolbarTitle;
    float ratio;
    int startHeight;

    int toolbarTitleYPosition = -1;
    String imageUrl;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        setupViews();
        getIntentId();
        txtToolbarTitle.setTranslationY(150);
       // observeForDetail();
    }

    private void getIntentId() {
        id = getIntent().getExtras().getString("id");
    }



    private void setupViews() {

        txtToolbarTitle = findViewById(R.id.txt_detail_toolbarTitle);
        imgImage = findViewById(R.id.img_detail_image);
        toolbar = findViewById(R.id.rel_detail_toolbar);




        ratingModels = new ArrayList<>();
        txtDescription = findViewById(R.id.txt_detail_description);
        imgShare = findViewById(R.id.img_detail_share);
        imgFav = findViewById(R.id.img_detail_favorite);
        imgBack = findViewById(R.id.img_detail_back);
        imgMore = findViewById(R.id.img_detail_more);
        imgMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupMenu popupMenu=new PopupMenu(DetailActivity.this,imgMore);
                popupMenu.getMenuInflater().inflate(R.menu.detail_more_menu,popupMenu.getMenu());
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        if(menuItem.getItemId()==R.id.action_more_chart){
                            Intent intent=new Intent(getApplicationContext(), ChartActivity.class);
                            intent.putExtra("id",id);
                            intent.putExtra("title",title);
                            startActivity(intent);
                        }else{
                            Intent intent=new Intent(getApplicationContext(), CompareActivity.class);
                            intent.putExtra("image_url",imageUrl);
                            startActivity(intent);
                        }
                        return true;
                    }
                });

                popupMenu.show();
            }
        });
        imgCart = findViewById(R.id.img_detail_cart);
        txtTitle = findViewById(R.id.txt_detail_title);
        txtName = findViewById(R.id.txt_detail_name);
        txtColor = findViewById(R.id.txt_detail_color);
        txtguarantee = findViewById(R.id.txt_detail_guarantee);
        txtPrice = findViewById(R.id.txt_detail_price);
        txtPoints = findViewById(R.id.txt_detail_points);
        txtMore = findViewById(R.id.txt_detail_more);
        txtMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (txtMore.getText().toString().equals("ادامه مطلب")) {
                    startHeight = txtDescription.getHeight();
                    txtDescription.setMaxLines(Integer.MAX_VALUE);
                    int widthSpec = View.MeasureSpec.makeMeasureSpec(txtDescription.getWidth(), View.MeasureSpec.EXACTLY);
                    int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                    txtDescription.measure(widthSpec, heightSpec);
                    int targetHeight = txtDescription.getMeasuredHeight();
                    final int heightSpan = targetHeight - startHeight;
                    txtDescription.getLayoutParams().height = startHeight;
                    txtDescription.setLayoutParams(txtDescription.getLayoutParams());
                    Animation animation = new Animation() {
                        @Override
                        protected void applyTransformation(float interpolatedTime, Transformation t) {
                            txtDescription.getLayoutParams().height = (int) (startHeight + heightSpan * interpolatedTime);
                            txtDescription.setLayoutParams(txtDescription.getLayoutParams());
                        }
                    };
                    animation.setDuration(300);
                    txtDescription.startAnimation(animation);
                    txtMore.setText("بستن");
                } else {
                    startHeight = txtDescription.getHeight();
                    txtDescription.setMaxLines(8);
                    int widthSpec = View.MeasureSpec.makeMeasureSpec(txtDescription.getWidth(), View.MeasureSpec.EXACTLY);
                    int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                    txtDescription.measure(widthSpec, heightSpec);
                    int targetHeight = txtDescription.getMeasuredHeight();
                    final int heightSpan = targetHeight - startHeight;
                    txtDescription.getLayoutParams().height = startHeight;
                    txtDescription.setLayoutParams(txtDescription.getLayoutParams());
                    Animation animation = new Animation() {
                        @Override
                        protected void applyTransformation(float interpolatedTime, Transformation t) {
                            txtDescription.getLayoutParams().height = (int) (startHeight + heightSpan * interpolatedTime);
                            txtDescription.setLayoutParams(txtDescription.getLayoutParams());
                        }
                    };
                    animation.setDuration(300);
                    txtDescription.startAnimation(animation);
                    txtMore.setText("ادامه مطلب");
                }

            }
        });
        properties = findViewById(R.id.card_detail_properties);
        properties.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(DetailActivity.this, PropertiesActivity.class);
                intent.putExtra("title", title);
                startActivity(intent);
            }
        });
        comments = findViewById(R.id.card_detail_comments);
        comments.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), CommentActivity.class);
                intent.putExtra("id",id);
                intent.putExtra("name",txtName.getText().toString());
                startActivity(intent);
            }
        });

        btnAddToBasket = findViewById(R.id.btn_detail_addToBasket);
        recyclerView = findViewById(R.id.rv_detail_points);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        ratingBar = findViewById(R.id.rating_detail);


    }

    @Override
    protected void onDestroy() {
        compositeDisposable.dispose();
        super.onDestroy();
    }
}

это xml коды:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:background="@color/gray200"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Detail.DetailActivity">

    <RelativeLayout
        android:id="@+id/rel_detail_toolbar"
        android:background="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">


        <ImageView
            android:layout_centerVertical="true"
            android:layout_margin="8dp"
            android:id="@+id/img_detail_back"
            android:layout_alignParentRight="true"
            app:srcCompat="@drawable/ic_arrow_back_24dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


        <ImageView
            android:layout_centerVertical="true"
            android:layout_margin="8dp"
            app:srcCompat="@drawable/ic_more_vert_black_24dp"
            android:id="@+id/img_detail_more"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ImageView
            android:layout_centerVertical="true"
            app:srcCompat="@drawable/ic_shopping_cart_black_24dp"
            android:layout_toRightOf="@id/img_detail_more"
            android:id="@+id/img_detail_cart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_alignParentBottom="true"
            android:textColor="@color/colorWhite"
            android:text="test test"
            android:layout_marginRight="8dp"
            android:layout_toLeftOf="@id/img_detail_back"
            android:id="@+id/txt_detail_toolbarTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScroll_detail"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">




            <ImageView
                android:background="#ffffff"
                android:id="@+id/img_detail_image"
                android:layout_width="match_parent"
                android:layout_height="200dp" />

            <android.support.v7.widget.CardView
                app:cardBackgroundColor="@color/gray100"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RelativeLayout
                    android:paddingBottom="8dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/img_detail_share"
                        android:layout_margin="8dp"
                        app:srcCompat="@drawable/ic_share_black_24dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <ImageView
                        android:layout_margin="8dp"
                        app:srcCompat="@drawable/ic_favorite_black_24dp"
                        android:layout_toRightOf="@+id/img_detail_share"
                        android:id="@+id/img_detail_favorite"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:ellipsize="end"
                        android:layout_below="@id/img_detail_share"
                        android:maxLines="1"
                        android:minLines="1"
                        android:textColor="@color/colorBlack"
                        android:layout_marginRight="8dp"
                        android:layout_alignParentRight="true"
                        tools:text="هارد اکسترنال سیلیکن پاور 1 ترا بایت"
                        android:id="@+id/txt_detail_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:layout_marginRight="8dp"
                        android:layout_alignParentRight="true"
                        tools:text="هارد اکسترنال سیلیکن پاور 1 ترا بایت"
                        android:textSize="12sp"
                        android:id="@+id/txt_detail_name"
                        android:layout_width="wrap_content"
                        android:layout_below="@id/txt_detail_title"
                        android:layout_height="wrap_content" />
                </RelativeLayout>
            </android.support.v7.widget.CardView>



            <LinearLayout
                android:background="@color/gray200"
                android:gravity="center"
                android:padding="16dp"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v7.widget.CardView
                    android:layout_marginRight="4dp"
                    android:foreground="?android:selectableItemBackground"
                    android:layout_width="0dp"
                    android:id="@+id/card_detail_comments"
                    android:layout_weight="0.5"
                    android:layout_height="wrap_content">

                    <LinearLayout
                        android:gravity="center"
                        android:padding="8dp"
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:textColor="@color/gray700"
                            android:layout_marginRight="8dp"
                            android:text="نظرات کاربران"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" />

                        <ImageView
                            app:srcCompat="@drawable/ic_comment_black_24dp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" />

                    </LinearLayout>
                </android.support.v7.widget.CardView>
                <android.support.v7.widget.CardView
                    android:layout_marginLeft="4dp"
                    android:foreground="?android:selectableItemBackground"
                    android:layout_weight="0.5"
                    android:id="@+id/card_detail_properties"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content">

                    <LinearLayout
                        android:gravity="center"
                        android:padding="8dp"
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:textColor="@color/gray700"
                            android:layout_marginRight="8dp"
                            android:text="مشخصات"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" />

                        <ImageView
                            app:srcCompat="@drawable/ic_comment_black_24dp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" />

                    </LinearLayout>
                </android.support.v7.widget.CardView>


            </LinearLayout>

            <android.support.v7.widget.CardView
                app:cardElevation="4dp"
                android:layout_marginRight="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginBottom="16dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:layout_marginRight="8dp"
                        android:textSize="16sp"
                        android:layout_gravity="right"
                        android:textColor="@color/colorBlack"
                        android:text="رنگ"
                        android:id="@+id/txt_detail_colorTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                    <TextView
                        android:layout_marginRight="8dp"
                        android:layout_gravity="right"
                        tools:text="مشکی"
                        android:id="@+id/txt_detail_color"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                    <TextView
                        android:layout_margin="8dp"
                        android:layout_gravity="right"
                        tools:text="گارانتی سه ساله ۀوا"
                        android:id="@+id/txt_detail_guarantee"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                    <View
                        android:background="@color/gray300"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"/>
                    <TextView
                        android:textColor="@color/red"
                        android:layout_margin="8dp"
                        android:layout_gravity="right"
                        android:text="فروش توسط دیجی کالا"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:layout_margin="8dp"
                        android:layout_gravity="right"
                        android:text="آماده ارسال از انبار دیجی کالا"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                    <View
                        android:background="@color/gray300"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"/>

                    <TextView
                        android:id="@+id/txt_detail_price"
                        android:layout_margin="8dp"
                        android:textColor="@color/green"
                        tools:text="1230000 تومان"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <Button
                        android:id="@+id/btn_detail_addToBasket"
                        android:layout_margin="8dp"
                        android:textColor="@color/colorWhite"
                        android:text="افزودن به سبد خرید"
                        android:background="@drawable/shape_btn_add_to_basket"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:drawableLeft="@drawable/ic_keyboard_arrow_left_black_24dp"
                        android:drawablePadding="8dp"
                        android:drawableRight="@drawable/ic_account_balance_black_24dp"
                        android:layout_gravity="center"
                        android:text="8 فروشنده و گارانتی برای این کالا وجود دارد"
                        android:textColor="@color/colorAccent"
                        android:layout_width="wrap_content"
                        android:layout_marginBottom="8dp"
                        android:layout_height="wrap_content" />
                </LinearLayout>


            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                app:cardElevation="4dp"
                android:layout_margin="16dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


                    <TextView
                        android:maxLines="6"
                        android:ellipsize="end"
                        android:padding="16dp"
                        android:textColor="@color/colorBlack"
                        tools:text="محصولی با دوام و با کیفیت عالی همراه با ضمانت نامه"
                        android:id="@+id/txt_detail_description"
                        android:layout_width="match_parent"
                        android:layout_height="170dp" />

                    <View
                        android:background="@color/gray200"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"/>

                    <TextView
                        android:id="@+id/txt_detail_more"
                        android:padding="8dp"
                        android:text="ادامه مطلب"
                        android:layout_gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                </LinearLayout>


            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                app:cardElevation="4dp"
                android:layout_margin="16dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RelativeLayout
                    android:padding="8dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <RatingBar
                        style="?android:attr/ratingBarStyleSmall"
                        android:layout_centerHorizontal="true"
                        android:progressTint="@color/red"
                        android:rating="3.5"
                        android:id="@+id/rating_detail"
                        android:numStars="5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                    <TextView
                        android:id="@+id/txt_detail_points"
                        android:layout_marginLeft="8dp"
                        android:layout_toRightOf="@id/rating_detail"
                        tools:text="3.5 از 5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <android.support.v7.widget.RecyclerView
                        android:layout_margin="8dp"
                        android:layout_below="@id/rating_detail"
                        android:id="@+id/rv_detail_points"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
                </RelativeLayout>

            </android.support.v7.widget.CardView>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>


</LinearLayout>

1 Ответ

0 голосов
/ 25 июня 2019

Можете ли вы изменить фон NestedScrollView и сделать фон как Android: background = "@ color / gray200".Должно работать нормально.

...