Immersive mode leaving slightly transparent white bar when hiding navigation - java

When entering full screen immersive mode, there is a lighter portion where the navigation bar was
Here is my XML layout file:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.QuoteActivity">
<TextView
android:id="#+id/quote"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:fontFamily="#font/din_light"
android:gravity="center_horizontal"
android:text=""Quote""
android:textColor="#FFFFFF"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/quote_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/din_light"
android:gravity="center_horizontal"
android:text="- Author"
android:textColor="#FFFFFF"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/quote" />
</androidx.constraintlayout.widget.ConstraintLayout>
These are the flags I use to enter immersive mode :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quote);
this.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
This is my styles.xml :
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#drawable/bg_2880x1440</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">#drawable/ls_2880x1440</item>
</style>
</resources>
I am not using android:fitsSystemWindows="true" anywhere in my program.
The white strip is not part of my background.
When I screenshot it, it goes away (image is recreation of what it looks like in app)
This also happens at the top but it is less noticeable.
So my question is, how do I get rid of this?

Related

#20 in com.example.hellocompat:layout/activity_main: Error inflating class TextView .....in android

Installation successful but App launch fails and logcat show this error "#20 in com.example.hellocompat:layout/activity_main: Error inflating class TextView"
One thing I noticed, is that if I used this same layout to some other project then it ran very smoothly without having any frustrating issue and that projects also having the same code as in themes.xml file.
Code inside MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void changeColor(View view) { // onClick method
}
}
activity_main.xml looks like this
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:text="Hello World!"
android:textSize="#string/textView_text_size"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeColor"
android:text="#string/change_color"
android:textSize="#string/button_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.HelloCompat" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
As #Nitish told , we need to use dimen to pass int value to textSize. And it just solved the problem.
And #GabeSechan's point is also right as stack trace having real error below this exception. Have a look.

set Label Alignment in navigation Fragments

I want the label(toolbar title) to be aligned centered.What should I do? I have reffered to some logics and didn't find them effective and they also didn't work. So kindly guide me through it.
This is the Navigation File:
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
app:startDestination="#id/current_weather_fragment">
<fragment
android:id="#+id/current_weather_fragment"
android:name="com.example.wheatherapp.UI.Weather.CurrentWeather.CurrentWeatherFragment"
android:label="current_weather_fragment"
tools:layout="#layout/current_weather_fragment" />
<fragment
android:id="#+id/future_weather_fragment"
android:name="com.example.wheatherapp.UI.Weather.FutureWeather.FutureWeatherListFrag.FutureWeatherFragment"
android:label="future_weather_fragment"
tools:layout="#layout/future_weather_fragment" />
<fragment
android:id="#+id/future_detail_weather"
android:name="com.example.wheatherapp.UI.Weather.FutureWeather.FutureDetailFrag.FutureDetailWeather"
android:label="future_detail_weather_fragment"
tools:layout="#layout/future_detail_weather_fragment" />
<fragment
android:id="#+id/setting_fragment"
android:name="com.example.wheatherapp.UI.Setting.SettingFragment"
android:label="SettingFragment" />
</navigation>
This is the MainActvity.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UI.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:theme="#style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_frag"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/appbar_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#id/bottom_nav"
app:navGraph="#navigation/mobile_navigation"
app:defaultNavHost="true"
android:name="androidx.navigation.fragment.NavHostFragment" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/bottom_nav_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
This is the image in which i want the title to be aligned centered:
the uploaded one
Style.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.WheatherApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ToolbarTheme" parent="ThemeOverlay.MaterialComponents.ActionBar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#EEEEEE</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="background">?colorPrimary</item>
</style>
</resources>
1) Add Textview for your toolbar title into your tag which is located in MainActivity.xml in your case.
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:theme="#style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Borrowers"
android:textColor="#color/white"
android:textSize="18dp" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
2) Add toolbar to your MainActivity.java in onCreate() method.
//set toolbar
Toolbar toolbar = findViewById(R.id.borrowerstoolbar_main);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);

Change action bar icon position

I want to display the menu icon to left of the toolbar and the search icon to be in the actual place of the menu icon
This is my main.xml file inside the main folder
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/my_search"
android:icon="#drawable/ic_search_black_24dp"
android:title="search"
app:showAsAction="always">
</item>
<item
android:id="#+id/my_menu_icon"
android:icon="#drawable/ic_menu_black_24dp"
android:title="side_menu"
app:showAsAction="always">
</item>
</menu>
This is the result of this page:
my result
And this is my MainActivity.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);//affect the menu file to the main activity and call this last one
return true;
}
}
I prefer use Toolbar instead of ActionBar, and Customize layout in xml form. you can change AppTheme like this inside /src/main/res/values/style.xml:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
do not forget to set AppTheme in manifest, like this:
<application
android:theme="#style/AppTheme"
//and other properties
</application>
then you can use android Toolbar inside layouts:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:orientation="horizontal">
<ImageButton
android:id="#+id/menu_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/ic_menu_black_24dp""/>
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="left"
android:text="App Title"
android:textSize="16dp"
android:textStyle="bold"/>
<ImageButton
android:id="#+id/search_btn"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/ic_search_black_24dp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
// and other views
// .
// .
// .
</android.support.design.widget.CoordinatorLayout>

Scroll to EditText in NestedScrollView is not working

I have long scroll form, and I need to scroll to its position on form is not valid input (for example, scroll to email edit text when it's not valid email or empty field)
I am facing 2 issues with scroll to EditText inside NestedScrollView
When one edit text is focused, all times scroll to take me directly to the focused scroll view, not to provided view coordinate
When there is no focused item, it's scrolling in a bad way, the wanted Edittext showing trimmed from the button
Note: I am using NestedScrollView with CoordinateLayout
Below is the layout
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/full_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f6f5">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="9dp"
android:layout_marginStart="9dp"
android:layout_marginTop="25dp"
android:text="#string/personal_details"
android:textColor="#a1143c"
android:textSize="14sp" />
<RelativeLayout
android:id="#+id/step1.rel.full_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/step.1.title.full_name"
style="#style/business_form_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/firstName" />
<EditText
android:id="#+id/step.1.feild.full_name"
style="#style/business_form_field"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="#+id/step.1.title.full_name"
android:inputType="textPersonName" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/step1.rel.last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/step.1.title.last_name"
style="#style/business_form_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/last_name" />
<EditText
android:id="#+id/step.1.feild.last_name"
style="#style/business_form_field"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="#+id/step.1.title.last_name"
android:inputType="textPersonName" />
</RelativeLayout>
<!--Rest Of Views-->
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
here is the style
<style name="business_form_field">
<item name="android:background">#drawable/roundedallsideswhite</item>
<item name="android:layout_marginStart">9dp</item>
<item name="android:layout_marginEnd">9dp</item>
<item name="android:textColor">#383838</item>
<item name="android:textSize">14sp</item>
<item name="android:gravity">start|center_vertical</item>
<item name="android:imeOptions">actionNext</item>
<item name="android:singleLine">true</item>
<item name="android:inputType">textAutoComplete</item>
<item name="android:paddingStart">15dp</item>
<item name="android:paddingEnd">15dp</item>
<item name="android:lines">1</item>
<item name="android:maxLines">1</item>
<item name="android:layout_marginTop">10dp</item>
</style>

Delete blue line in View android API 16

I need delete a blue line that appears in my application when I compile with API 20 or higher but doesn't appear when I compile in API < 20.
This image shows the blue line I need delete.
that is mi code view XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="0dp"
android:background="#color/transparent"
android:layout_height="280dp" >
<net.simonvt.numberpicker.NumberPicker
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary"
android:id="#+id/numberPicker1_popup"
android:singleLine="true"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:configChanges="keyboard|keyboardHidden"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/title_picker"
android:layout_alignStart="#+id/title_picker"
android:layout_alignRight="#+id/title_picker"
android:layout_alignEnd="#+id/title_picker" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:text=""
android:id="#+id/button_cancel"
android:layout_below="#+id/numberPicker1"
android:layout_alignParentLeft="true"
android:layout_marginLeft="15dp"
android:layout_alignParentStart="false"
android:background="#drawable/big_cancel"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/button_ok"
android:layout_alignTop="#+id/button_cancel"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp"
android:background="#drawable/big_ok_line_green"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:id="#+id/title_picker"
android:layout_marginTop="0dp"
android:layout_alignLeft="#+id/button_cancel"
android:layout_alignStart="#+id/button_cancel"
android:layout_alignRight="#+id/button_ok"
android:layout_alignEnd="#+id/button_ok"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:textAlignment="center"
android:textColor="#000000"/>
</RelativeLayout>
and this is my style
<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>
<item name="numberPickerStyle">#style/NPWidget.Holo.Light.NumberPicker</item>
<item name="android:typeface">monospace</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NowindowTitle">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
thanks for helpme
You need to customize your view appearance by setting background , etc if you want to remove that blue line . Because that is the default appearance for that platform (which I guess is started since Honeycomb).

Categories