I'm using a BottomSheetDialogFragment however when I show it, part of it is being cut off at the bottom.
Why isn't it fully inflating and how can I fix this?
Heres the full layout and usage:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="#+id/fragplaces_app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingTop="16dp"
android:paddingEnd="12dp"
android:paddingBottom="16dp"
android:text="test"
android:textColor="#color/colorWhite"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
android:background="#drawable/background_top_round_corners_blue"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/fragnearme_recycler"
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#color/backgroundColor"
android:paddingBottom="8dp"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="#+id/fragplaces_app_name"
app:layout_constraintBottom_toTopOf="#+id/send_msg_layout"/>
<RelativeLayout
android:id="#+id/send_msg_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/backgroundColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:paddingBottom="8dp">
<ImageView
android:id="#+id/btn_emoji"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:srcCompat="#drawable/ic_grey_smiley_24dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"/>
<EditText
android:id="#+id/challengeroom_et_sendmessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#id/btn_emoji"
android:background="#drawable/background_chat_send_message"
android:gravity="center_vertical"
android:hint="Type a message"
android:inputType="text"
android:maxLines="1"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textColorHint="#color/defaultTextColor"
android:textSize="14sp" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Usage:
BottomSheetDialogFragment chatFragment = new ChatFragment();
chatFragment.show(getSupportFragmentManager(), Constants.FRAGMENT_CHAT);
I've tried changing the parent constraint layout height to match_parent and have also tried setting it to a defined height like 500dp, however it still doesn't work.
Adding <item name="behavior_peekHeight">500dp</item> in my BottomSheetDialog's style fixed the issue.
<style name="BottomSheetRoundedCorners" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#drawable/background_top_round_corners</item>
<item name="behavior_peekHeight">500dp</item>
</style>
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/BottomSheetRoundedCorners</item>
<item name="behavior_draggable">false</item>
</style>
and using it in my main app theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="bottomSheetDialogTheme">#style/AppBottomSheetDialogTheme</item>
</style>
Credits to this answer:
https://stackoverflow.com/a/35720641/11110509
Related
Images of files to which I made changes after creating the project
image of themes.xml
image of colors.xml
Image of error
image of AndroidManifest.xml
Code from my activity_main.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="#drawable/ic_bg"
tools:context=".MainActivity">
<TextView
android:id="#+id/tv_app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="25sp"
android:gravity="center"
android:text="QuizBuzz"/>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="8dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#363A43"
android:textSize="16sp"
android:text="Welcome"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#7A8089"
android:textSize="18sp"
android:text="Please enter your name"
/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<androidx.appcompat.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#363A43"
android:textColorHint="#7A8089"
android:hint="Name"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/purple_500"
android:text="Start">
</Button>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Problem
When I am clicking the run button, I m getting an error (Image of error -from the 1st list)
I am new to android development. So I cannot understand what is exactly happening. Please help me pinpoint the problem.
if you need anything more please let me know. if you can help me with some online resources I will be grateful.
If you're using Jetpack Compose, then just remove the old themes files and add a single one that needs this content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.YourProject" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">#color/purple_700</item>
</style>
</resources>
And to set the theme also in AndroidManifest file.
Try this:
Add these missing colors to your colors.xml file:
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
The layout in a full screen dialog is not rendered properly.
This is my dialog code:
val mDialogView = LayoutInflater.from(this).inflate(R.layout.alertdialog_info, null)
val mBuilder = AlertDialog.Builder(this, R.style.FullScreenDialog)
.setView(mDialogView)
val mAlertDialog = mBuilder.show()
mDialogView.titleTv.text = getString(R.string.title)
mDialogView.descriptionTv.text = getString(R.string.description)
mAlertDialog.show()
in style.xml this is my FullScreenDialog:
<style name="FullScreenDialog" parent="android:Theme.Dialog">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
</style>
And this is my layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="16dp"
android:gravity="bottom"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/md_white_1000">
<ImageView
android:id="#+id/iconIv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:src="#drawable/ic_success"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#id/titleTv" />
<TextView
android:id="#+id/titleTv"
style="#style/FontLocalizedBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="#string/payment_success"
android:textColor="#color/colorTextPrimary"
android:textSize="24sp"
android:layout_marginStart="24dp"
android:gravity="center"
android:layout_marginEnd="24dp"
android:maxLines="2"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<TextView
android:id="#+id/descriptionTv"
style="#style/FontLocalizedMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="24dp"
android:gravity="center"
tools:text="#string/payment_success_description"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/titleTv" />
<TextView
android:id="#+id/okTv"
style="#style/ButtonTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:paddingBottom="16dp"
android:background="#drawable/save_button_active"
android:text="#string/done"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have tried with LinearLayout instead of ConstraintLayout, but same result.
I have attached pictures with how my xml file look, and how it looks rendered on emulator, ignore please different string values.
emulator:
xml:
Any idea what can cause the difference in rendering?
Sounds like you need to update the preview style in the xml viewer. I highlighted the drop down box to use in the current release of AndroidStudio.
I want to show the mentioned things center in the dialog, for example, now one of them is showing like this:
And it should show like this:
I mean, the same space above the bitmap and under the button.
The same should apply to the width of the bitmap, the same space should be left to the left and to the right, my current code seems to achieve that.
This is how I call the dialog:
private fun showFullScreenDialog()
{
val vacationDialog = AlertDialog.Builder(fragment.context,R.style.DialogTheme)
val factory = LayoutInflater.from(fragment.context);
var view = factory.inflate(R.layout.sample, null)
view.dialog_imageview.setImageBitmap(bitmap)
vacationDialog.setView(view)
vacationDialog.setPositiveButton("Cerrar"){dialog, which ->
dialog.dismiss()
}
vacationDialog.show()
}
This is sample.xml layout:
<LinearLayout 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_gravity="center_horizontal"
android:gravity="center_horizontal"
android:background="#color/white"
>
<ImageView
android:id="#+id/dialog_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:foregroundGravity="center_vertical"
/>
</LinearLayout>
And this the defined DialogTheme style:
<style name="DialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">#color/colorPrimary</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
</style>
Any idea on how to solve this issue?
use relative layout instead of linear layout-:
<RelativeLayout 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_gravity="center_horizontal"
android:gravity="center_horizontal"
android:background="#color/white"
>
<ImageView
android:id="#+id/dialog_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:foregroundGravity="center_vertical"
/>
</LinearLayout>
If none of other solutions work, try to delete the xml layout and create a new one. The android studio sometimes gets buggy.
I use Constraint Layout to centre anything:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".YourActivity">
<ImageView
android:id="#+id/dialog_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.constraint.ConstraintLayout>
I am facing a problem of getting null in getSupportActionBar(),
when setting toolbar as actionbar in an activity and setting the back button programmatically from supportActionBar, the exception I get is,
Attempt to invoke virtual method 'void android.app.ActionBar' on a null object reference
here is the xml view of the activity, the toolbar is included from another layout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar_ftp"
android:id="#+id/include" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="#+id/include"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_alignParentBottom="true"
android:id="#+id/below_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:background="#color/white">
<TextView
android:layout_below="#+id/line11"
android:id="#+id/txt_search_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_margin="16dp"
android:text="#string/search_by_Date"/>
<RelativeLayout
android:id="#+id/rl_cal_pick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_search_date"
>
<ImageView
android:id="#+id/icon_secheudel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/rlBoxtime"
android:layout_alignBottom="#+id/rlBoxtime"
android:src="#mipmap/ic_clock_red"
android:tint="#color/colorPrimary"/>
<RelativeLayout
android:id="#+id/rlBoxtime"
android:layout_toRightOf="#+id/icon_secheudel"
android:background="#drawable/blue_out_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="3dp"
android:paddingTop="3.5dp"
android:paddingBottom="3.5dp"
android:layout_marginLeft="0dp">
<TextView
android:id="#+id/txt_chosen_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:minWidth="30dp"
android:text=""/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/txt_chosen_date"
android:layout_centerVertical="true"
android:src="#mipmap/ic_calendar_schedule"
android:tint="#color/colorAccent"
android:layout_marginRight="2.5dp"/>
</RelativeLayout>
</RelativeLayout>
<TextView
android:id="#+id/btn_tommorow"
android:text="#string/tommorow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:gravity="center"
android:layout_alignTop="#+id/rl_cal_pick"
android:layout_alignBottom="#+id/rl_cal_pick"
android:layout_toRightOf="#+id/tvTOday"
android:textColor="#color/colorAccent"
android:padding="5dp"
android:background="#drawable/blue_out_line"
style="#style/borderless_blue_text_button"
/>
<TextView
android:id="#+id/tvTOday"
android:text="#string/today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:gravity="center"
android:padding="5dp"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/rl_cal_pick"
android:layout_alignBottom="#+id/rl_cal_pick"
android:layout_toRightOf="#+id/rl_cal_pick"
android:textColor="#color/colorAccent"
android:background="#drawable/blue_out_line"
android:layout_marginRight="8dp"/>
</RelativeLayout>
</RelativeLayout>
Here is the toolbar_ftp.xml file
<android.support.v7.widget.Toolbar 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/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:scaleType="centerInside"
android:src="#drawable/ftp_home_logo"
tools:ignore="ContentDescription" />
</android.support.v7.widget.Toolbar>
Here is the toolbar code
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
hi try to change theme style of your app
<!-- 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/colorPrimary</item>
<item name="android:textColor">#color/black</item>
<item name="android:actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
</style>
I tried all the solutions posted here, Still, I was experiencing the crash. Later I figured out the problem, It was because of giving an additional id in the include statement of the xml view.
<include layout="#layout/toolbar_ftp"
android:id="#+id/include" />
When referencing the toolbar, it became ambiguous for id inside id.
In most of the cases this problem can be caused by your theme. Check it again, and make sure that it's parent with Theme.AppCompat.Light.DarkActionBar.
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
...
</style>
If your activity extends AppCompatActivity or ActionBarActivity, then you must call getSupportActionBar().
if you are using AppcompatActivity try this :
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if you are using ActionBarActivity then try this :
this.getActionBar().setDisplayHomeAsUpEnabled(true);
I have created a custom toolbar which has a spinner. I am trying to set a custom colour for the spinner arrow - currently the default is white, but it's not working, any ideas?
This is my Toolbar layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/newToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:elevation="0dp"
android:windowContentOverlay="#null"
android:orientation="horizontal">
<ImageView
android:id="#+id/strLogo"
android:layout_width="45dp"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:scaleType="fitCenter"
android:visibility="gone"
android:background="#ffffff"
android:src="#mipmap/logo"/>
<TextView
android:id="#+id/updateName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:layout_toRightOf="#+id/strLogo"
android:layout_centerVertical="true"
android:text="Test"
android:visibility="visible"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<Spinner
android:id="#+id/spinner_nav"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
style="#style/customSpinnerTheme"
android:visibility="visible"/>
</RelativeLayout>
This my style xml for the spinner:
<style name="customSpinnerTheme" parent="ThemeOverlay.AppCompat">
<item name="colorControlActivated">#FFFFFF</item>
<item name="colorControlHighlight">#FFFFFF</item>
</style>
You can add this type of style in your spinner style and add your colors which you want to use as your drawable:
<style name="SpinnerAppTheme" parent="android:Widget.Spinner">
<item name="android:background">#drawable/apptheme_spinner_background_holo_light</item>
<item name="android:dropDownSelector">#drawable/apptheme_list_selector_holo_light</item>
</style>