android does not detect white color and

mojtaba nekooei

New member
Jun 26, 2019
1
0
0
Visit site
I have a problem,but no one could help me.the problem is: I have detail activity for show details of my product. this activity has a toolbar(relative layout) with white background color. everything is good and no problem but when I come from a fragment to this detail activity my toolbar color turn to blue! I try to check what is the reason, and I finally detect my application does not know the white color!! if I use the #ffffff (hardcode or get from resource) my toolbar turn to blue but if I use any other color, it's okay even #fffffe

xml codes:

Code:
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:fontFamily">@font/font</item>
        <item name="fontFamily">@font/font</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>


detail activity codes:

Code:
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;


    [MENTION=93274]overr[/MENTION]ide
    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() {
            [MENTION=93274]overr[/MENTION]ide
            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() {
                    [MENTION=93274]overr[/MENTION]ide
                    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() {
            [MENTION=93274]overr[/MENTION]ide
            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() {
                        [MENTION=93274]overr[/MENTION]ide
                        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() {
                        [MENTION=93274]overr[/MENTION]ide
                        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() {
            [MENTION=93274]overr[/MENTION]ide
            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() {
            [MENTION=93274]overr[/MENTION]ide
            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);


    }

    [MENTION=93274]overr[/MENTION]ide
    protected void onDestroy() {
        compositeDisposable.dispose();
        super.onDestroy();
    }

detail activity xml codes:

Code:
<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>
 

B. Diddy

Senior Ambassador
Moderator
Mar 9, 2012
165,274
4,385
113
Visit site
I moved this from the Android L Developer Preview forum (for the beta version of Lollipop) to the Software Development forum.
 

Trending Posts

Forum statistics

Threads
942,379
Messages
6,913,751
Members
3,158,382
Latest member
gkapidis