I'm trying to create a fullscreen (but status bar has to still be visible) Dialog with custom transparent (same as this answer https://stackoverflow.com/a/29482234), but my background is not transparent.
I've wasted 2 days trying all solution, but it just won't work. My goal is to show a dialog with custom dim color (instead of default black). The answer above looked like what I needed but I can't get it to work. Any suggestions?
My code:
<style name="CustomDialogTheme2" parent="#android:style/Theme.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AAFFFFFF">
<RelativeLayout
android:id="#+id/dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#CCFF0000"
android:padding="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout>
</FrameLayout>
DialogFragment:
public class TestDialogFrag extends DialogFragment {
public static TestDialogFrag newInstance() {
Bundle args = new Bundle();
TestDialogFrag fragment = new TestDialogFrag();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialogTheme2);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.test_dialog_frag, container, false);
return view;
}
}
Try the below, It will help you.
Layout File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center">
<LinearLayout
android:layout_width="260dp"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:id="#+id/dialog_universal_info_image"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#ff0000"
android:contentDescription="Imagg"
android:scaleType="centerCrop" />
<View
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#4cbdbcbc" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/app_name"
android:textColor="#android:color/white"
android:textAppearance="?android:textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="22dp"
android:paddingLeft="26dp"
android:paddingRight="26dp"
android:paddingTop="22dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/dialog_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="heare"
android:textColor="#android:color/holo_green_dark"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:id="#+id/dialog_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="4"
android:text="Content is here"
android:textColor="#android:color/holo_green_dark" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:background="#android:color/holo_blue_dark" />
<TextView
android:id="#+id/dialog_info_ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="OK"
android:textColor="#android:color/holo_green_dark"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
Java File
public class DialogUtilsInfo {
public Activity mDialogUniversalInfoActivity;
private Dialog mDialog;
private TextView mDiaappicon_48KButton;
public DialogUtilsInfo(Activity mDialogUniversalActivity) {
this.mDialogUniversalInfoActivity = mDialogUniversalActivity;
}
public void showDialog(String content) {
if (mDialog == null) {
mDialog = new Dialog(mDialogUniversalInfoActivity, R.style.CustomDialogTheme);
}
mDialog.setContentView(R.layout.dialog_info);
mDialog.setCancelable(true);
mDialog.show();
mDiaappicon_48KButton = (TextView) mDialog.findViewById(R.id.dialog_info_ok);
initDialogButtons1();
}
private void initDialogButtons1() {
mDiaappicon_48KButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
mDialog.dismiss();
}
});
}
public void dismissDialog() {
mDialog.dismiss();
}
}
Related
I am trying to set my custom dialog fragment to use the full width of the screen. The one solution is to set LayoutParams on view. But they are not working.
Things I Tried
Changing parent Layout
using getLayoutParams().getClass() which returns null
Layout Validator shows correct layout so no prob here, here is my Layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
style="#style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked"
android:id="#+id/ask_hint_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="#+id/puppy_vw"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<pl.droidsonroids.gif.GifImageView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:src="#drawable/solving"
android:adjustViewBounds="true">
</pl.droidsonroids.gif.GifImageView>
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked"
android:text="#string/ad_confirm_text"/>
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_below="#id/puppy_vw"
android:id="#+id/ad_confm_btns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_centerInParent="true">
<com.google.android.material.button.MaterialButton
android:id="#+id/yes_hint"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:text="Yes">
</com.google.android.material.button.MaterialButton>
<!--
<com.google.android.material.button.MaterialButton
android:id="#+id/no_hint"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:text="No">
</com.google.android.material.button.MaterialButton>
-->
<com.google.android.material.button.MaterialButton
android:id="#+id/why_hint"
android:layout_margin="5dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
android:text="Why Ads?">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
Here is my DialogFragment class
public class AdLoadFragment extends DialogFragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
AskHintDialogBinding binding=AskHintDialogBinding.inflate(inflater,container,false);
View view=binding.getRoot();
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MyUtilsApp.showLog(String.valueOf(view.getClass()));
view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
}
}
All my modal BottomSheets have a white background above them and are not transparent as intended.
I tried opening the view via a separate Fragment like this:
ContextMenuPlaylistFragment contextMenuPlaylistFragment = new ContextMenuPlaylistFragment();
contextMenuPlaylistFragment.show(fragmentManager,"contextmenu playlists");
and like that:
View modelBottomSheet = LayoutInflater.from(mContext).inflate(R.layout.context_menu_playlist, null);
BottomSheetDialog dialog = new BottomSheetDialog(mContext);
dialog.setContentView(modelBottomSheet);
dialog.show();
This is my BottomSheetFragment:
public class ContextMenuPlaylistFragment extends BottomSheetDialogFragment {
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.context_menu_playlist, container, false);
}
}
And this is my BottomSheet:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_playlist_search"
android:orientation="horizontal"
android:layout_marginBottom="15dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_search_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/search_playlist"
android:textSize="18sp"
android:layout_marginStart="10dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_playlist_rename"
android:orientation="horizontal"
android:layout_marginBottom="15dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_edit_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rename_playlist"
android:textSize="18sp"
android:layout_marginStart="10dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_playlist_delete"
android:orientation="horizontal"
android:layout_marginBottom="15dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_delete_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delete_playlist"
android:textSize="18sp"
android:layout_marginStart="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I put it in two LinearLayouts to try and make the background transparent.
I also tried it with one LinearLayout that doesn't change the background and has height "wrap_content"
Please check if you have set the android:background attribute in the "AppTheme" style to white. If so, delete it or set it to transparent will solve the problem.
I have found some questions regarding this issue here but none of them helped to solve my problem. Recycler view works fine but there is issue in lollipop version. It works perfectly in an activity but doesn't show or scroll when used inside fragment. My fragment screen appears blank but the tap listeners in recycler view's adapter is working. When I migrated my fragment code to an activity, it worked fine. I am using 28.0.0 Here is my xml code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeToRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/initial_layout_empty_view" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_order"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:nestedScrollingEnabled="false" />
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
My item xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/wholeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtVendorName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorTextListTitle"
android:textSize="16sp"
android:textStyle="bold"
tools:text="Redsun Family Restaurant" />
<TextView
android:id="#+id/txtVendorAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorTextNormal"
android:textSize="14sp"
android:textStyle="bold"
tools:text="KumariPati,Lalitpur,Nepal" />
</LinearLayout>
<ImageView
android:id="#+id/imageCompleted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_check_green"
android:visibility="gone" />
<Button
android:id="#+id/btnDeliveryStatus"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#drawable/circular_btn_background_dark_green"
android:backgroundTint="#color/colorPrimary"
android:text="Accept"
android:textColor="#color/white"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<include layout="#layout/layout_seperator" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:orientation="horizontal">
<include
android:id="#+id/included"
layout="#layout/layout_vendor_logo" />
<View
android:id="#+id/catLogoDivider"
android:layout_width="0.7dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#e8e8e8" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relOrderNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtLblOrderNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:text="#string/txtOrderNo"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtOrderNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/txtLblOrderNo"
android:gravity="end"
android:maxLines="2"
android:textColor="#color/black"
tools:text="#16-0131-102716" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relDeliveryTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtLblDeliveryTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:text="#string/txtDeliveryTime"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtDeliveryTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/txtLblDeliveryTime"
android:gravity="end"
android:maxLines="2"
android:textColor="#color/black"
tools:text="Jul 5, 2017, 7:15pm" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtLblStatus"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/txtStatus"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="end"
android:maxLines="2"
android:textSize="14sp"
android:textColor="#color/black"
tools:text="Processing" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtTotalAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:text="#string/txtTotalAmount"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtTotalAmountValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="#color/black"
tools:text="Rs. 197.50" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
And the long fragment code
public class OrderFragment extends MvpFragment<OrderView, OrderListPresenter> implements OrderView, OnItemClickListener {
private View view;
private Toolbar mToolbar;
private RecyclerView recyclerView;
private SwipeRefreshLayout swipeRefreshLayout;
private List<Order> orderList = new ArrayList<>();
private OrderAdaptor adaptor;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_order, container, false);
return view;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
findViews();
setActionBar();
initRecyclerView();
initSwipeToRefresh();
if (getActivity() != null)
getActivity().setTitle(getString(R.string.titleOrders));
presenter.getOrderData();
}
#Override
public OrderListPresenter createPresenter() {
return new OrderListPresenter(getContext());
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home)
if (getActivity() != null) {
((MainActivity) getActivity()).openDrawerLayout();
}
return super.onOptionsItemSelected(item);
}
#Override
public void setAdaptor(List<Order> orderList) {
hideLoading();
this.orderList.clear();
this.orderList.addAll(orderList);
adaptor.notifyDataSetChanged();
}
#Override
public void showLoading() {
swipeRefreshLayout.setRefreshing(false);
if (getActivity() != null)
ProgressDialogFactory.getInstance(getActivity()).show();
}
#Override
public void initSwipeToRefresh() {
swipeRefreshLayout.setOnRefreshListener(() -> {
showLoading();
presenter.getOrderData();
});
}
#Override
public void onItemClicked(int position) {
// Don't navigate if order is completed
if (!orderList.get(position).getStatusId().equals(Constants.ORDER_STATUS_DELIVERED))
GlobalUtils.navigateActivityWithMultipleData(getContext(), false, OrderDetailActivity.class, R.anim.slide_in_left, R.anim.no_change, orderList.get(position).getOrderId(), orderList.get(position).getStatusDisplay());
}
private void findViews() {
mToolbar = view.findViewById(R.id.mToolbar);
recyclerView = view.findViewById(R.id.recyclerView_order);
swipeRefreshLayout = view.findViewById(R.id.swipeToRefresh);
}
private void initRecyclerView() {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setHasFixedSize(true);
recyclerView.setVisibility(View.VISIBLE);
adaptor = new OrderAdaptor(orderList, this);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(adaptor);
recyclerView.setNestedScrollingEnabled(false);
}
private void setActionBar() {
if (getActivity() == null)
return;
setHasOptionsMenu(true);
((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
}
}
God Damn! After being stuck in this issue for 2 whole days, I finally found the solution. It was because I was using FragmentTransaction.TRANSIT_FRAGMENT_FADE when adding fragment inside activity. Removing the transition solved my problem
Want to add something to Dialog's backdrop like
I tried to read all the documents but can't find a way to add check in text to the backdrop.
I have done it like this, hope it will help
Layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:calendar="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="#+id/mainLayout"
android:layout_height="match_parent"
android:layout_marginBottom="#dimen/fifty_five_dp"
android:background="#android:color/transparent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/twenty_dp"
android:layout_marginTop="#dimen/one_twenty_dp"
android:layout_marginRight="#dimen/twenty_dp"
calendar:cardCornerRadius="#dimen/three_dp"
calendar:cardElevation="#dimen/two_dp"
calendar:cardPreventCornerOverlap="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/fifty_five_dp"
android:background="#color/dull_white"
android:padding="#dimen/thirteen_dp"
android:textSize="#dimen/sixteen_sp">
<TextView
android:id="#+id/leaveFromTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:fontFamily="#font/sf_pro_display_bold"
android:text="#string/select_leaves_placeholder"
android:textColor="#color/darkGreyDeepDeep"
android:textSize="#dimen/sixteen_sp" />
<TextView
android:id="#+id/leaveCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:fontFamily="#font/sf_pro_display_bold"
android:text="#string/days_placeholder"
android:textColor="#color/darkGrey"
android:textSize="#dimen/twelve_sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:calendar="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/seven_dp"
android:layout_marginTop="#dimen/fifteen_dp"
android:background="#drawable/box"
android:padding="#dimen/ten_dp">
<RelativeLayout
android:id="#+id/okayLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/thirteen_dp">
<ImageView
android:id="#+id/calenderDrawable"
android:layout_width="#dimen/seventeen_dp"
android:layout_height="#dimen/seventeen_dp"
android:layout_centerVertical="true"
android:src="#mipmap/calener" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/ten_dp"
android:layout_toRightOf="#+id/calenderDrawable"
android:text="Calender"
android:textColor="#color/blue_light"
android:textSize="#dimen/fourteen_sp" />
<Button
android:id="#+id/btnDone"
android:layout_width="#dimen/seventy_dp"
android:layout_height="#dimen/twenty_six_dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="#dimen/three_dp"
android:background="#drawable/calender_button_background"
android:text="DONE"
android:textColor="#color/white"
android:textSize="#dimen/thirteen_sp" />
</RelativeLayout>
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/okayLayout"
android:layout_marginTop="#dimen/ten_dp"
android:background="#color/viewColor" />
<com.neomeric.nock.com.andexert.calendarlistview.library.DayPickerView
android:id="#+id/pickerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/view"
android:layout_marginTop="#dimen/ten_dp"
android:background="#color/dull_white"
calendar:enablePreviousDay="false" />
</RelativeLayout>
</LinearLayout>
DatePickerPopup.java
public class DatePickerPopup extends DialogFragment implements DatePickerController {
private DayPickerView dayPickerView;
public DatePickerPopup() {
// Empty constructor is required for DialogFragment
// Make sure not to add arguments to the constructor
// Use `newInstance` instead as shown below
}
public static DatePickerPopup newInstance(OnDatesSelected datesSelected, Date first, Date last) {
DatePickerPopup frag = new DatePickerPopup();
Bundle args = new Bundle();
frag.setArguments(args);
return frag;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.date_selection_layout, container);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
return root;
}
public void setDateAndDaysCount(SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays) {
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public int getMaxYear() {
return 2021;
}
#Override
public void onDayOfMonthSelected(int year, int month, int day) {
}
#Override
public void onStart() {
super.onStart();
// To make it match parent
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
#Override
public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays) {
}
}
How it looks
Make a linear layout with 2 internal layouts, where the upper one will have a transparent background and the other one will have the content.
<?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="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#android:color/transparent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
app:srcCompat="#drawable/ic_clock" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_margin="10dp"
android:background="#000000"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
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>