BottomAppBar height gets bigger when using window.setDecorFitsSystemWindows(false) - height

I am trying to achieve transparent status bar by using window.setDecorFitsSystemWindows(false) and statusBarColor = Color.TRANSPARENT. I achieved my goal, but when I introduced BottomAppBar, its size (padding to be exact) is doubled. What might be the issue?
With window.setDecorFitsSystemWindows(false):
Without window.setDecorFitsSystemWindows(false):
Main Activity Layout:
<?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=".ActivityMain">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainer"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:defaultNavHost="true"
app:navGraph="#navigation/main" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:elevation="1dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemHorizontalTranslationEnabled="false"
android:background="#android:color/transparent"
app:elevation="0dp"
app:labelVisibilityMode="auto"
app:menu="#menu/nav_bar_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Got to the answer quickly than I thought I would. I forgot to calculate the insets, so adding this piece of code made everything working again:
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(bottom = insets.bottom)
WindowInsetsCompat.CONSUMED
}

Related

How to set up Chip and ChipGroup attributes properly?

I figured out that app: namespace attributes are not applied to Chip view in my project, though documentation and some sample code I have seen state that they do. What do I do wrong?
<com.google.android.material.chip.Chip
style="#style/Widget.Material3.Chip.Filter"
android:id="#+id/chip1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginHorizontal="20dp"
app:chipStrokeColor="#F0F"
app:chipStrokeWidth="1dp"
app:chipBackgroundColor="#color/biz_500"
app:chipMinHeight="48dp"
app:chipCornerRadius="7dp"
android:text="#string/text_input_girl"
android:textSize="11sp"
android:textAlignment="center" />
I also use Theme.Material3.Light.NoActionBar in application manifest.
I tried to switch to MaterialComponents, but it looks even worse.
Chips Attitude is Normal
<com.google.android.material.chip.Chip
style="#style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="#dimen/_10sdp"
android:text="#string/app_name"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_10sdp"
android:textStyle="bold"
app:checkedIcon="#drawable/ic_close_24"
app:checkedIconEnabled="false"
app:checkedIconTint="#color/white"
app:checkedIconVisible="true"
app:chipBackgroundColor="#color/purple_500"
app:chipCornerRadius="#dimen/_10sdp"
app:chipEndPadding="#dimen/_10sdp"
app:chipIconSize="#dimen/_100sdp"
app:chipMinTouchTargetSize="#dimen/_50sdp"
app:closeIcon="#drawable/ic_close_24"
app:rippleColor="#color/white" />
Chip Four Type
style="#style/Widget.MaterialComponents.Chip.Entry"
style="#style/Widget.MaterialComponents.Chip.Action"
style="#style/Widget.MaterialComponents.Chip.Choice"
style="#style/Widget.MaterialComponents.Chip.Filter"

How to make ToolBar and StatusBar Gradient

how can I make ToolBar and StatusBar Gradient as shown image1 This one I want but I'm getting StatusBar and ToolBar as image2 like this. If you observed in 1st image the ToolBar is full gradient at endColor position(bottom of the ToolBar) but 2nd image of the ToolBar is not full Gradient as 1st image at bottom of the ToolBar and showing as a straight line. My code is as given below:
#drawable:
toolbar_product_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:type="linear"
android:angle="270"
android:startColor="#44000000"
android:centerColor="#22000000"
android:endColor="#00000000"/>
</shape>
AppBarLayout with ToolBar
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="#null"
android:theme="#style/AppTheme.Transparent"
android:background="#drawable/toolbar_product_gradient" >
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarProduct"
android:layout_width="match_parent"
android:layout_height="56dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:contentScrim="#android:color/transparent"
app:expandedTitleTextAppearance="#android:color/transparent"
app:titleEnabled="true"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
Please help me how to get it and thanks in advance.

ActionBar with Search and One more option

I would like to add 2 menu options to the action bar. One is Search and the other is custom one. When I tried to add, the 2nd option is always going to over flow menu only. But I want that to be displayed always as below.
But it's being displayed as
Here is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_search"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_search"
android:title="#string/action_search"
yourapp:actionViewClass="android.support.v7.widget.SearchView"
yourapp:showAsAction="ifRoom|collapseActionView"/>
<item
android:id="#+id/action_add_new_event"
android:icon="#drawable/ic_refresh"
android:showAsAction="ifRoom|withText"
android:title="#string/action_add_new_event"/>
</menu>
Any idea about how can I achieve this? Thanks in advance.
I just modified the below code
<item
android:id="#+id/action_add_new_event"
android:icon="#drawable/ic_refresh"
android:showAsAction="ifRoom|withText"
android:title="#string/action_add_new_event"/>
to
<item
android:id="#+id/action_add_new_event"
android:icon="#drawable/ic_refresh"
yourapp:showAsAction**="ifRoom|withText"
android:title="#string/action_add_new_event"/>
and it worked.

How to make a listview transparent?

I have a listview activity with a bunch of single textview items. Here's my item:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#FFFFFF"
android:background="#00000000"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
As you can see, the text color is white, and the background is transparent. (I tried putting alpha from 0 to 100, it either shows white background or black)
Now in the listview, I have put in an image in the background called "s4":
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/s4">
</ListView>
I want to make the listview items sort of translucent such that the background image can be viewed.
Each item should be translucent, the text should be white and visible, and the listview's background should be visible.
I can't seem to get it right, I can put in a solid color, but I want the items to scroll over a fixed background image.
What am I doing wrong?
Try like this.......... Put your text view with linear layout and set background color for your layout.......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="280dp"
android:layout_height="30dp"
android:background="#F1F1F1"
android:orientation="horizontal" >
<TextView
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#FFFFFF"
android:background="#00000000"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
</LinearLayout>

keeping data during orientation changes by using fragments

I am trying to understand fragments. All the examples I read is about having a main activity and then two sub fragments.
The issue is that my program has only 1 activity. Can I make it a fragment?
Current ui main class
public class MainActivity extends Activity {}
Can I make it
public class MainActivity extends Fragment {}
The program I am trying to create will constantly monitor phone variables and display logs in a textView. I don't want to lose the logs when the user changes the orientation or some other change when the os destroys the ui.
The UI is basically 1 textView that gets filled by a runnable that updates the textView every 5 seconds with the content of a linked list. I don't want to lose the content of the linked list basically.
I checked getLastNonConfigurationInstance() but it seems it's depreciated so I don't want to use that
Any help would be highly appreciated.
Amish
Found answer here:
http://blog.webagesolutions.com/archives/458
So after a lot of searching I found that if you add the following:
android:configChanges="orientation|screenSize"
in the androidManifest.xml, the os will not destroy the activity when switching from portrait mode to landscape mode.
My xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.axr0284.phonecontrol"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.axr0284.phonecontrol.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hope this helps somebody,
Amish