Material FloatingActionButton inside CoordinatorLayout is not showing in the design preview window - material-design

I am using material FloatingActionButton inside CoordinatorLayout with androidx libraries, but my design window is not showing anything. Here is the code that I have tried:
<?xml version="1.0" encoding="utf-8"?>
<androidx.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">
<!-- Main content -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
app:srcCompat="#drawable/ic_add_white_24dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Related

android studio expandable bottom sheet with recycleview

I'm trying to achieve something like this:
as you can see the bottom sheet is expandable when there is more than one line of the recycleview.
I want to implement the same thing in the profile page so that if posts are more than three lines then I can expand the bottom sheet, then I can scroll the recycleview (when the sheet is expanded).
my current xml:
<LinearLayout
android:id="#+id/allPosts"
android:layout_below="#+id/userinfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:background="#drawable/rounded_behind_recycleview"
android:orientation="vertical"
android:elevation="1dp">
<com.taimoorsikander.myapplication.Widgets.B_RecycleView
android:id="#+id/recycle_view"
android:overScrollMode="never"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</LinearLayout>
^
it looks like the image I attached but it is not expandable yet.
is this possible in Android Studio? if yes, please help.
In this tutorial they teach you how to set the Behaviour in the BottomSheetFragment,
take a look it's really helpful, there you will find how to set the Behaviour that you want with BottomSheetBehaviour.from(...)...
Kotlin language
Basically you have to set the height(Ex: peekHeight = 50) you want than and set "false" to hide the bottomSheet and "true" to (isDraggable).
There is 2 ways of doing this declarative in the XML or programmatically, I'll show the first:
1º Your first layout needs to be CoordinatorLayout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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=".MainActivity">
<include layout="#layout/bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
2º The bottomSheetLayout:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_hideable="false"
app:behavior_peekHeight="100dp"
app:behavior_skipCollapsed="true"
app:layout_behavior="#string/bottom_sheet_behavior">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardBackgroundColor="#81D4FA" />
</LinearLayout>
Pay attention to this TAGS, which states the behavior and state of the BottomSheet:
app:behavior_hideable="false"
app:behavior_peekHeight="100dp"
app:behavior_skipCollapsed="true"
app:layout_behavior="#string/bottom_sheet_behavior"

Why Relativelayout doesn't work on fragments?

I have created a bottom navigation bar from this tutorial https://www.youtube.com/watch?v=JS3DIb4x1JQ&t=1352s, but RelativeLayout doesn't work properly on fragments.
Here is the code of bluetooth fragment with textview in the middle:
<?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:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:id="#+id/bluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#0472FE"
android:text="Bluetooth"
android:textSize="30dp"
android:layout_centerInParent="true"
/>
</RelativeLayout>
This is what it looks like in
design
And this is what it looks like in
android emulator
How do I fix it?
Are there other components in this view? check the main view if it set to match_parent.

how to make sure the color fill in the entire bottom navigation view?

I'm facing a problem right now that i tried to imply the color function background in the app:itemBackground="#color/purpleBoo"
but the color seems like not to fill in the entire bottom navigation? why is this happening to me?
my bottom navigation code
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/purpleBoo"
app:menu="#menu/bottom_nav_menu"
app:itemIconTint="#color/bottom_nav_color"
app:itemTextColor="#color/bottom_nav_color"/>
</RelativeLayout>
For the current layout that you are using the bottom navigation panel can be maximized to width "match_parent" so the color will also be available inside the width section.
Well, in case the white space around the panel is disturbing the look of your app then you can change the background of the layout as a whole then that would seem better.
Just add the android android:background="#color/purpleBoo" in BottomNavigationView
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/purpleBoo"
app:menu="#menu/bottom_nav_menu"
android:background="#color/purpleBoo"
app:itemIconTint="#color/bottom_nav_color"
app:itemTextColor="#color/bottom_nav_color"/>
</RelativeLayout>

How to remove extra padding at top of window?

I have this strange padding-top when I run my App on Android. On iOS it looks as expected.
When I check the padding is 0 for all directions. My last thought is that it could be related to some of my layouts, but I don't understand what that could be.
Toolbar layout:
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"/>
Tabs layout
<?xml version="1.0" encoding="UTF-8"?>
<android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="#android:color/white"
app:tabGravity="fill"
app:tabMode="fixed" />
I am using Xamarin.Form's MasterDetailPage with my pages being ContentPage.
Does this combination of pages create this error on Android? Please help me fix it.
Here is a screenshot of what I see:
]1
You're able to change lots of settings in Android Solution (MainActivity.cs) just underneath your namespace.
For example:
[Activity(Theme = "#style/AppStyle.Light", Label = "ProjectName", MainLauncher = false,
ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

Material Design Toolbar CustomView RelativeLayout

RelativeLayout doesn't seem to play nice in the v7 support library. I have three elements, One is aligned to the bottom and the other two stack above it. Rather than appear nicely stacked at the bottom, they are rendered off screen, this is unexpected.
I've included an example XML file which is for the custom view added to the toolbar.
<?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">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name"
android:layout_above="#+id/divider"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textColor="#color/textLighter"
android:text="#string/example_sequence_name"
android:singleLine="true" />
<View
android:id="#+id/divider"
android:layout_width="wrap_content"
android:background="#color/textLighter"
android:layout_above="#+id/description"
android:layout_height="81dp"/>
<EditText
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_description"
android:textAppearance="#style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
android:textColor="#color/textLighter"
android:layout_alignParentBottom="true"
android:singleLine="true" />
Results in this view.

Resources