My application does not detect white color - android

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
it is my style:
<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>
detailactivity 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;
#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 codes:
<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>

What is activity theme in style , if you do not set noActionBar theme android put default toolbar on your relative layout and you cant see it
So define your styles like this
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/activityBackground</item>
<item name="colorPrimaryDark">#color/greyTextColor</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and set AppTheme.NoActionBar bar theme to your activity in AndroidManifest file
Or Use
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>

Try using -
android:background="#android:color/white"

You may wanna try that; define a new color to the "colors.xml" and use it as background.
Update
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
You should change your #color/colorPrimary and #color/colorPrimaryDark with the colors you want. Define them in colors and assign them instead of those two above. It must be fixed. Good Luck!

You have two choice
1) you can set your toolbar color in your detail activity onCreate
toolbar.setBackgroundColor(Color.WHITE);
check this may this works or
2) in color.xml set white color and get the reference from there
"< color name="colorTransWhite">#ffffffff< /color>" (remove extra spaces)
check any of one and let me know if not work.

Related

Android Custom Dialog, no matter the width specified it stays the same

I have a custom Dialog, which I inflate and use. Now I wanted to have rounded corners which proves to be rather difficult. And it seems that one of those hacks made it so my Dialog doesn't change size no matter if the width is WrapContent, 10dp, 20dp, 200dp or 300dp. It changes in the layout editor but when I actually launch the app it stays the same.
Editor
InApp
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/dialog_background"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Do you want to reset progress?"
android:textColor="#color/black"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/cancel_button"
style="#style/basicButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:backgroundTint="#color/delete_red"
android:padding="10dp"
android:text="Cancel"
android:textColor="#color/white"
android:textSize="20sp" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/confirm_button"
style="#style/basicButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Yes"
android:textSize="20sp" />
<nearLayout>
</LinearLayout>nearLayout>
</LinearLayout>
And this is where I build it (note the links in the comments, I think that's what causes the problems, setting the background of the window).
val builder = AlertDialog.Builder(requireContext())
val dialogBinding = ResetProgressDialogBinding.inflate(layoutInflater)
builder.setView(dialogBinding.root)
val dialog = builder.create()
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)); // https://stackoverflow.com/questions/28937106/how-to-make-custom-dialog-with-rounded-corners-in-android
dialogBinding.root.clipToOutline = true // https://issuetracker.google.com/issues/37036728
And my shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#color/white"/>
<corners
android:radius="10dp" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
I'm using PopupHelper class you can use this code:
public class PopUpHelper {
static Dialog dialog;
public static void showDialog(Activity activity, PINConfirmButtonClickListener action) {
if (dialog != null && dialog.isShowing()) {
boolean isShowing = dialog.isShowing();
return;
}
dialog = new Dialog(activity, R.style.MyAlertDialogStyle);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.(your_dialog_layout);
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
dialog.show();
dialog.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
action.onPositiveClicked()
"YOUR_ACTION_HERE"
}
});
dialog.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
action.onNegative()
"YOUR_ACTION_HERE"
}
});
dialog.findViewById(R.id.close_dialog_rl).setOnClickListener(view -> action.onCloseButtonClicked(dialog));
dialog.findViewById(R.id.resend_code_tv).setOnClickListener(view -> action.onResendCodeClicked());
}
public interface TwoButtonClickListener {
void onPositiveClicked(Dialog dialog);
void onNegativeClicked(Dialog dialog);
}
}
MyDialogStyle: (Add to styles.xml)
<!-- Alert Dialog Style-->
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<!-- Used for the border radius -->
<item name="android:bottomLeftRadius">5dp</item>
<item name="android:bottomRightRadius">5dp</item>
<item name="android:topRightRadius">5dp</item>
<item name="android:topLeftRadius">5dp</item>
<item name="android:autofilledHighlight" tools:targetApi="o">#color/transparent</item>
</style>
and in activity calling Popup :
PopUpHelper.showDialog(this, new PopUpHelper.TwoButtonClickListener() {
#Override
public void onPositiveClicked(Dialog dialog) {
dialog.dismiss();
startHomeActivity();
}
#Override
public void onNegativeClicked(Dialog dialog) {
dialog.dismiss();
}
});
if background transparent not working set "android:background="#android:color/transparent" to dialog layout
Example my layout but you can delete fonts and some fields:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#android:color/transparent"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp">
<androidx.cardview.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32.5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="25dp"
android:paddingVertical="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:orientation="vertical"
android:paddingTop="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/bold"
android:gravity="center"
android:lineSpacingExtra="4dp"
android:text="#string/add_to_cart"
android:textColor="#color/color_secondary"
android:textSize="18sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="#font/medium"
android:lineSpacingExtra="4dp"
android:gravity="center"
android:text="#string/product_added_to_cart"
android:textColor="#color/color_secondary_60"
android:textSize="14sp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/action_button"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#color/orange_light"
android:ellipsize="end"
android:fontFamily="#font/medium"
android:foreground="?selectableItemBackground"
android:gravity="center"
android:letterSpacing="0.05"
android:singleLine="true"
android:text="#string/add_to_cart"
android:textColor="#color/white"
android:textSize="16sp"/>
<TextView
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:id="#+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:ellipsize="end"
android:fontFamily="#font/medium"
android:foreground="?selectableItemBackground"
android:gravity="center"
android:letterSpacing="0.05"
android:singleLine="true"
android:text="#string/cancel"
android:textColor="#color/color_secondary_60"
android:textSize="13sp"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<RelativeLayout
android:id="#+id/close_dialog_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/card_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#drawable/shape_circle_white">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_close"
app:tint="#color/white"/>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:id="#+id/confetti_v"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/shape_circle_orange"
android:padding="16dp"
android:src="#drawable/ic_check_white"
app:tint="#color/white"/>
</RelativeLayout>
</LinearLayout>

Android fullscreen dialog

I am following https://blog.alexanderschaefer.io/android-material-full-screen-fragment-dialog to make a full screen dialog.
full_screen_dialog_layout
<?xml version="1.0" encoding="utf-8"?>
<android.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:paddingEnd="16dp"
android:paddingStart="6dp"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="#drawable/ic_close_white_24dp"
android:paddingRight="16dp"
android:paddingLeft="6dp" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello I am a dialog!" />
</FrameLayout>
</android.coordinatorlayout.widget.CoordinatorLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreenDialog" parent="Theme.MaterialComponents.Light.Dialog">
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="actionMenuTextColor">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
FullScreenDialog.java
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.darekeapp.R;
public class FullScreenDialog extends DialogFragment {
private Toolbar toolbar;
public static FullScreenDialog display(FragmentManager fragmentManager) {
FullScreenDialog fullScreenDialog = new FullScreenDialog();
fullScreenDialog.show(fragmentManager, "example_dialog");
return fullScreenDialog;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_FullScreenDialog);
}
#Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.full_screen_dialog_layout,
container);
toolbar = view.findViewById(R.id.toolbar);
return view;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FullScreenDialog.this.dismiss();
}
});
toolbar.setTitle("Some Title");
toolbar.inflateMenu(R.menu.full_screen_dialog_menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
FullScreenDialog.this.dismiss();
return true;
}
});
}
}
Home.java
...
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
FullScreenDialog.display(getSupportFragmentManager());
}
});
...
popup_add_shift_log.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="#+id/company_name_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/company_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/company_name"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.SwitchCompat
android:id="#+id/worked_for_agent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:checked="true"
android:text="#string/worked_for_agent"
android:textSize="18sp"
android:textOn="#string/yes"
android:textOff="#string/no"
android:layout_below="#id/company_name_text_input_layout" />
<android.support.design.widget.TextInputLayout
android:id="#+id/agent_name_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/worked_for_agent"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/agent_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/agent_name"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatTextView
android:id="#+id/shift_start_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/agent_name_text_input_layout"
android:text="#string/shift_start"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/shift_start_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/shift_start_question"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/shift_end_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/shift_start_time"
android:text="#string/shift_end"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/shift_end_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/shift_end_question"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/break_taken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:checked="true"
android:text="#string/break_taken"
android:textSize="18sp"
android:textOn="#string/yes"
android:textOff="#string/no"
android:layout_below="#id/shift_end_time" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/break_start_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/break_taken"
android:text="#string/break_start_time"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/break_start_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/break_start_text"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/break_end_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/break_start_time"
android:text="#string/break_end_time"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/break_end_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/break_end_text"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/transport_job"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:checked="true"
android:text="#string/transport_job"
android:textSize="18sp"
android:textOn="#string/yes"
android:textOff="#string/no"
android:layout_below="#id/break_end_time" />
<android.support.design.widget.TextInputLayout
android:id="#+id/transport_company_name_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/transport_job"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/transport_company_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/transport_company_name"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/vehicle_registration_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/transport_company_name_text_input_layout"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/registration_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/vehicle_registration"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
</ScrollView>
I am trying to make the full screen dialog be displayed when the FAB (floating action button) is clicked. I want to set the view as the popup_add_shift_log. The app keeps crashing with various types of error, anything you can see I am doing wrong in the code
Pass dialog object to this Method.
public void resizeDialogToFullscreen(Dialog dialog) {
if (dialog != null && dialog.getWindow() != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}

Why images are displayed with light grey background, when it has white android?

When I am displaying image in ImageView using Glide, grey color is added in background.I have tried setting background color to transparent and even white in ImageView in my xml file..
But It is still not working..It is happening with every image I display in various activities.
Below is the screenshot of same image displayed in iPhone and Android Oreo.
Below is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/second"
android:layout_width="match_parent"
android:layout_height="240dp"
android:background="#fff">
<LinearLayout
android:id="#+id/bklayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="28dp"
android:paddingTop="8dp">
<ImageView
android:id="#+id/bkbutton"
android:layout_width="35dp"
android:layout_height="50dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:srcCompat="#drawable/ic_keyboard_arrow_left_black_24dp"/>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="35dp" />
<LinearLayout
android:id="#+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/viewPager"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/second"
android:id="#+id/third"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_marginTop="2dp"
android:background="#color/new_grey">
</View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.9"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:orientation="vertical">
<TextView
android:id="#+id/product_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Name: "
android:textColor="#android:color/black"
android:textSize="18sp" />
<com.example.unsan.grouponebuy.helpers.ExpandableTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
android:id="#+id/desc"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:id="#+id/fav"
android:padding="5dp"
app:srcCompat="#drawable/ic_favorite_grey_24dp" />
<TextView
android:id="#+id/favtext"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/favorite"
android:textColor="#color/grey_dark" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:textColor="#color/orange" />
<TextView
android:id="#+id/origprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/specification" />
<TextView
android:id="#+id/specification"
android:layout_marginLeft="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="8dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/origin" />
<TextView
android:id="#+id/origin"
android:layout_marginLeft="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/replacement_layout"
android:layout_marginLeft="8dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_check_box_green_24dp"/>
<TextView
android:layout_marginLeft="5dp"
android:text="#string/replacement_policy"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="visible"
android:orientation="vertical"
android:id="#+id/prodCartLayout">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="2dp"
android:background="#color/grey"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:layout_width="45dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:id="#+id/carticonbutton"
android:src="#drawable/cart_bl" />
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"></View>
<Button
android:id="#+id/carttext"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingRight="5dp"
android:paddingLeft="3dp"
android:gravity="center_vertical"
android:background="#color/red"
android:textSize="16sp"
android:text="#string/add_to_cart"
android:textColor="#android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="#string/outOfStock"
android:layout_marginRight="8dp"
android:layout_marginTop="12dp"
android:textColor="#color/grey"
android:id="#+id/soldout_text"
android:visibility="gone"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/prodSelectedLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="gone">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="2dp"
android:background="#color/new_grey"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
>
<ImageView
android:layout_width="45dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:id="#+id/carticonbutton2"
android:src="#drawable/cart_bl" />
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"></View>
<ImageView
android:id="#+id/sub_quantity"
android:layout_width="30dp"
android:layout_height="50dp"
android:layout_marginTop="4dp"
android:src="#drawable/minus" />
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="12dp"
android:text="1"
android:textSize="18sp" />
<ImageView
android:id="#+id/add_quantity"
android:layout_width="30dp"
android:layout_height="50dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="5dp"
android:layout_marginTop="4dp"
android:src="#drawable/add_on" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
My Java Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.product_detail);
backButton = (ImageView) findViewById(R.id.bkbutton);
cartImageButton = (ImageView) findViewById(R.id.carticonbutton);
cartButton2 = (ImageView) findViewById(R.id.carticonbutton2);
viewPager = (ViewPager) findViewById(R.id.viewPager);
productNameText = (TextView) findViewById(R.id.product_name);
originText = (TextView) findViewById(R.id.origin);
specText = (TextView) findViewById(R.id.specification);
favText = (TextView) findViewById(R.id.favtext);
favImgView = (ImageView) findViewById(R.id.fav);
priceText = (TextView) findViewById(R.id.price);
soldOutText = (TextView) findViewById(R.id.soldout_text);
quantityText = (TextView) findViewById(R.id.quantity);
addButton = (ImageView) findViewById(R.id.add_quantity);
subButton = (ImageView) findViewById(R.id.sub_quantity);
originalPriceText = (TextView) findViewById(R.id.origprice);
descriptionText = (ExpandableTextView) findViewById(R.id.desc);
cartLinearLayout = (LinearLayout) findViewById(R.id.prodCartLayout);
productSelectedLayout = (LinearLayout) findViewById(R.id.prodSelectedLayout);
cartAddButton = (Button) findViewById(R.id.carttext);
replacementLayout = (LinearLayout) findViewById(R.id.replacement_layout);
listViews = new ArrayList<>();
indicator = (LinearLayout) findViewById(R.id.indicator);
globalProvider = GlobalProvider.getGlobalProviderInstance(getApplicationContext());
buyNumView = new CircleBadgeView(this, cartButton2);
buyNumView.setTextColor(Color.WHITE);
buyNumView.setBackgroundColor(Color.RED);
numBadge = new CircleBadgeView(this, cartImageButton);
numBadge.setBackgroundColor(Color.RED);
//cycleTextViewExpansion(descriptionText);
// expandCollapsedByMaxLines(descriptionText);
backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent returnIntent = new Intent();
returnIntent.putExtra("productupdated", product);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
});
Intent intent = getIntent();
product = (Product) intent.getSerializableExtra("product");
List<String> imgList = product.getImageDisplay();
if (Constants.getLanguage(this).equals("english")) {
String origin = product.getOriginEn();
productNameText.setText(product.getNameEn());
originText.setText(origin);
;
specText.setText(product.getSpecificationEn());
if (product.getDescriptionEn() != null) {
descriptionText.setText(product.getDescriptionEn());
}
} else {
productNameText.setText(product.getNameCh());
originText.setText(product.getOriginCh());
specText.setText(product.getSpecificationCh());
if (product.getDescriptionCh() != null) {
descriptionText.setText(product.getDescriptionCh());
}
}
boolean prodSelected = false;
priceText.setText("$ " + product.getPrice());
listViews.clear();
indicator.removeAllViews();
if (imgList.size() > 0)
{
for (int a = 0; a < imgList.size(); a++) {
ViewGroup pager = (ViewGroup) getLayoutInflater().inflate(R.layout.viewpager_image, null);
ImageView imageView = (ImageView) pager.findViewById(R.id.viewpagerimg);
/* if (a == 0) {
imageView.setTransitionName(imgTransitionName);
}
*/
Glide.with(ProductDetailActivity.this).load(Constants.baseUrlStr + imgList.get(a)).override(500, 500).centerCrop().into(imageView);
listViews.add(pager);
}
productDetailViewPagerAdapter = new ProductDetailViewPagerAdapter(listViews, this);
viewPager.setAdapter(productDetailViewPagerAdapter);
if (imgList.size() > 1) {
for (int a = 0; a < imgList.size(); a++) {
if (a == 0) {
ImageView imgView = new ImageView(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(15, 15);
imgView.setLayoutParams(lp);
imgView.setImageResource(R.drawable.selected_dot);
indicator.addView(imgView);
} else {
ImageView imgView = new ImageView(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(15, 15);
lp.setMargins(20, 0, 0, 0);
imgView.setLayoutParams(lp);
imgView.setImageResource(R.drawable.default_dot);
// imgs.add(img);
indicator.addView(imgView);
}
}
} else {
ImageView img = new ImageView(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams
(15, 15);
//lp.setMargins(5,0,0,0);
img.setLayoutParams(lp);
img.setImageResource(R.drawable.selected_dot);
//imgs.add(img);
indicator.addView(img);
}
}
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener()
{
#Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
for (int i = 0; i < indicator.getChildCount(); i++) {
if (i == position) {
((ImageView) indicator.getChildAt(i)).setImageResource(R.drawable.selected_dot);
} else {
((ImageView) indicator.getChildAt(i)).setImageResource(R.drawable.default_dot);
}
}
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
}
Below is theme of my app:
<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:buttonStyle">#style/Button</item>
</style>
<style name="Button" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
</resources>
Solution:
Whichever parent layout you have placed your ImageView such as <LinearLayout> or <RelativeLayout> or <ConstraintLayout>, they all have a Default color code as #FAFAFA which is not exactly White and that one of the possible reason that
White's color code as you might already know is #FFFFFF.
So your answer lies in your layout, make the background color of your parent layout in which your ImageView resides as White #FFFFFF as shown below:
<LinearLayout
android:id="#+id/bklayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="28dp"
android:paddingTop="8dp"
android:background="#FFFFFF">
<ImageView
android:id="#+id/bkbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
UPDATE: Add the below line in your Glide as described Here
.dontTransform()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
Try it, I hope this is the problem.
Finally Found a solution..It was Glide's issue
https://github.com/bumptech/glide/issues/853
Using DiskCacheStrategy.SOURCE and DecodeFormat.PREFER_ARGB_8888 had resolve this problem.

RelativeLayout in DialogFragment - MarginBottom is ignored

So basically, I have this DialogFragment that is fullscreen and has a button over a progressbar (if you click the button, it disappears and the progressbar is visible). I initially had the xml in an activity and everything worked as expected there, but now I want to refactor it to a fullscreen dialogfragment.
Problem is, the button that was ontop of the progressbar is now aligned to the bottom of the parentLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/activity_gps_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_setsensor"
tools:ignore="MissingPrefix"
>
<ImageView
android:layout_width="90dp"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:orientation="vertical"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_location"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="17dp"
android:gravity="center_horizontal"
android:text="#string/promptGpsPermissionBody"
style="#style/fullscreenText"
/>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnActivateGps"
android:layout_alignTop="#+id/btnActivateGps"
style="?android:attr/progressBarStyle"
/>
<Button
android:id="#+id/btnActivateGps"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp"
android:layout_marginLeft="63dp"
android:layout_marginRight="63dp"
android:background="#color/white"
android:enabled="true"
android:visibility="visible"
/>
</RelativeLayout>
What's especially weird is that the progressbar is aligned to the button, but it's still located at the same position as before
here is the java-code
public class GpsSensorDialog extends DialogFragment {
#NonNull #Override public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.activity_gps_sensor, null);
builder.setView(view);
Dialog dialog = builder.create();
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow()
.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
return dialog;
}
#Override public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_TITLE, R.style.CustomDialog);
}
public static GpsSensorDialog newInstance() {
Bundle args = new Bundle();
GpsSensorDialog fragment = new GpsSensorDialog();
fragment.setArguments(args);
return fragment;
}
#Override public void onStart() {
super.onStart();
getDialog().getWindow()
.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
}
and the Style I set in onCreate
<style name="CustomDialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
Try this layout. Also, change your drawables, style and strings accordingly.
<RelativeLayout 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:id="#+id/activity_gps_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/ic_launcher"
tools:ignore="MissingPrefix">
<ImageView
android:layout_width="90dp"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="17dp"
android:gravity="center_horizontal"
android:text="obsdas" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnActivateGps" />
<Button
android:id="#+id/btnActivateGps"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp"
android:layout_marginLeft="63dp"
android:layout_marginRight="63dp"
android:background="#android:color/white"
android:enabled="true"
android:visibility="visible" />
</RelativeLayout>

Change background color of header in DialogFragment android

I have DialogFragment, which show some information. It's work nice, but I need different header, I need white Title color text and blue background of the header.
This is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_teacher"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/teacher"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_teacher"
android:layout_toRightOf="#+id/icon_teacher"
android:layout_toEndOf="#+id/icon_teacher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/teacher_name"
android:layout_below="#+id/teacher"
android:layout_alignLeft="#+id/teacher"
android:layout_alignStart="#+id/teacher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_time"
android:layout_below="#+id/icon_teacher"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/time"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_time"
android:layout_toRightOf="#+id/icon_time"
android:layout_toEndOf="#+id/icon_time" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/time_name"
android:layout_below="#+id/time"
android:layout_alignLeft="#+id/time"
android:layout_alignStart="#+id/time" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_place"
android:layout_below="#+id/icon_time"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/place"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_place"
android:layout_toRightOf="#+id/icon_place"
android:layout_toEndOf="#+id/icon_place" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/place_name"
android:layout_below="#+id/place"
android:layout_alignLeft="#+id/place"
android:layout_alignStart="#+id/place" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_home"
android:layout_below="#+id/icon_place"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/home"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_home"
android:layout_toRightOf="#+id/icon_home"
android:layout_toEndOf="#+id/icon_home" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/place_home"
android:layout_below="#+id/home"
android:layout_alignLeft="#+id/home"
android:layout_alignStart="#+id/home" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/divider1"
android:layout_below="#+id/icon_home"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/divider1"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:layout_marginLeft="10dp"
android:id="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/alert"
android:id="#+id/alert"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And my DialogFragment, but i think it won't be helpful so much:
public class LessonDialogFragment extends DialogFragment {
View view;
String title;
public LessonDialogFragment(String title) {
this.title = title;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.detail_dialog_fragment, container, false);
getDialog().setTitle(title);
return view;
}
}
I don't know how change it, maybe you can help me.
for custom layout:
https://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout
AlertDialog dialog = builder.show();
// Set title divider color
int titleDividerId = getResources().getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.findViewById(titleDividerId);
if (titleDivider != null)
titleDivider.setBackgroundColor(getResources().getColor(android.R.color.holo_purple));
Customising the background of the header is slightly more complex... You need to define in your theme an alertDialogStyle defining how you draw each area of the dialog. For example:
<style name="Theme.Yours" parent="#android:style/Theme.Holo">
...
<item name="android:alertDialogStyle">#style/AlertDialog_Yours</item>
</style>
<style name="AlertDialog_Yours">
<item name="android:fullDark">...</item>
<item name="android:topDark">...</item>
<item name="android:centerDark">...</item>
<item name="android:bottomDark">...</item>
<item name="android:fullBright">...</item>
<item name="android:topBright">...</item>
<item name="android:centerBright">...</item>
<item name="android:bottomBright">...</item>
<item name="android:bottomMedium">...</item>
<item name="android:centerMedium">...</item>
</style>

Categories

Resources