Keyboard beeing shown when pressing tab before button - android-studio

I'm very new to Android studio, and i'm trying to build a simple app that when I click a button, it does some calculations. The problem is that when I press tab on the last EditText before the button, the button become focused and a keyboard is shown, I just want the button to remain unfocusable so when the user input every necessary data, he can just click the button
What I tried is setting the property focusable and focusableInTouchMode to false but none of them seem to work and I havent found no other option that made sense for me.
What can I do to stop this behaviour?
Edit:
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rodolfo.trekking">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:windowSoftInputMode="stateHidden"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Edit 2:
XML Layout:
ersion="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="0dp"
android:inputType="number"
android:ems="10"
android:id="#+id/edTempo"
android:importantForAutofill="no"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView3" android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="#+id/textView" android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="#+id/textView"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/edTrecho"
android:importantForAutofill="no"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView2" android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="#+id/btCalcular" android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="#+id/btCalcular"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="0dp"
android:inputType="number"
android:ems="10"
android:id="#+id/edVelocidade"
android:importantForAutofill="no"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView" android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:text="#string/velocidade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_marginTop="64dp"
app:layout_constraintTop_toBottomOf="#+id/edTempo" app:layout_constraintStart_toStartOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="#+id/textView2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:text="#string/trecho"
app:layout_constraintStart_toStartOf="#+id/edTrecho"
app:layout_constraintEnd_toEndOf="#+id/edTrecho" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/edVelocidade"/>
<TextView
android:text="#string/tempo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="#+id/edTempo"
app:layout_constraintEnd_toEndOf="#+id/edTempo"/>
<Button
android:text="#string/calcular"
android:layout_width="210dp"
android:layout_height="42dp"
android:id="#+id/btCalcular" app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
tools:text="#string/calcular" android:layout_marginTop="84dp"
app:layout_constraintTop_toBottomOf="#+id/edTrecho" app:layout_constraintHorizontal_bias="0.487"
android:focusableInTouchMode="false"
style="#style/Widget.AppCompat.Button" android:autoText="false" android:editable="false"/>
</android.support.constraint.ConstraintLayou
t>

Set this in your manifest file
android:windowSoftInputMode="stateHidden"

Related

Android : adjustResize overlaps the views below the editText

I have a constraint layout as below:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
style="#style/LoginScreenBg"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/imageIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-100dp"
android:contentDescription="#null"
android:src="#drawable/ic_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="#id/dm_title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/dm_title"
style="#style/titlesp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
app:layout_constraintBottom_toTopOf="#id/username_input_layout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<EditText
android:id="#+id/username_input_layout"
style="#style/CreateAccountEditTextHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/EMAIL_HINT_TEXT"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toTopOf="#id/password_input_layout"
app:layout_constraintLeft_toLeftOf="parent"/>
<EditText
android:id="#+id/password_input_layout"
style="#style/CreateAccountEditTextHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/PASSWORD_HINT_TEXT"
android:inputType="textPassword"
android:maxLength="20"
app:layout_constraintBottom_toTopOf="#id/btn_login"
app:layout_constraintLeft_toLeftOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btn_login"
style="#style/LoginButton"
android:layout_width="match_parent"
android:layout_height="#dimen/generic_button_height"
android:layout_marginStart="#dimen/dp_16"
android:layout_marginEnd="#dimen/dp_16"
android:layout_marginBottom="#dimen/dp_24"
android:background="#color/login_button_color"
app:layout_constraintBottom_toTopOf="#+id/btn_forgot_username_password" />
<Button
android:id="#+id/btn_forgot_username_password"
style="#style/ForgotButton"
android:layout_width="wrap_content"
android:layout_height="#dimen/generic_button_height"
android:layout_marginBottom="#dimen/dp_24"
android:text="#string/FORGOT_USERNAME_PASSWORD_BUTTON"
app:layout_constraintBottom_toTopOf="#+id/btn_create_account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/btn_create_account"
style="#style/CreateAccountButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/dp_16"
android:layout_marginEnd="#dimen/dp_16"
android:layout_marginBottom="#dimen/dp_24"
android:text="#string/SCREEN_LOGIN_CREATE_ACCOUNT"
app:layout_constraintBottom_toBottomOf="parent"
app:uidComponentType="Secondary" />
<ProgressBar
android:id="#+id/progress_circular"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Below code is added in the manifest
<activity
android:name=".ui.Activity"
android:configChanges="screenSize|orientation|keyboard"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When we use the adjustResize, UI components gets overlapped with each other.
If I do not add the adjust resize there are few layouts which over the notification bar on my device.
If I add the adjust resize it is distorts the UI.
I am using single activity model. So the change in manifest will affect all the screens
Could you please let me know how to resolve this
This was happening because the views at the top of the screen are chained to each other but the button at the end is independent and is constrained to the bottom of the screen.
When the screen is resized, the elements are not chained to each other and the views are distorted

List view hide in emulator

I try to write a to-do list app using ListView. But there is a problem when I use the keyboard on my phone and try to add something to the list the first elements are not visible. After I add 3 or 4 elements, I am able to see the to-do list items. How I can adjust the listview that it won't go up when I use the keyboard.
Here is the XML code
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">
<ListView
android:id="#+id/listView"
android:layout_width="0dp"
android:layout_height="450dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:focusableInTouchMode="false"
android:isScrollContainer="false"
app:layout_constraintBottom_toTopOf="#+id/editText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.403" />
<Button
android:id="#+id/button"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="73dp"
android:background="#drawable/custom_button"
android:onClick="add"
android:text="+"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/editText" />
<EditText
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="75dp"
android:ems="10"
android:hint="Click to add..."
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/button"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

Tab indicator no longer at the bottom of AppBarLayout after migrating app to AndroidX. The tab is custom made tab

I migrated android app to AndroidX and then I noticed this
As you can see the tab indicator went up into the AppBarLayout. Here is the code
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay"
android:elevation="4dp">
<androidx.appcompat.widget.Toolbar
... // some code here relevant to toolbar
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/custom_tab" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/custom_tab" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/custom_tab"/>
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
The custom layout I created is below:
<?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="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="CONTRIBUTIONS"
style="#style/TextAppearance.Design.Tab"/>
<TextView
android:id="#+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/tab_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="1000"
android:layout_marginBottom="8dp"
style="#style/TextAppearance.Design.Tab"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:text="#string/open_bracket"
app:layout_constraintBottom_toBottomOf="#+id/tv_number"
app:layout_constraintEnd_toStartOf="#+id/tv_number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/tv_number"
app:layout_constraintHorizontal_bias="1"
style="#style/TextAppearance.Design.Tab"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="#string/closing_bracket"
app:layout_constraintBottom_toBottomOf="#+id/tv_number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/tv_number"
app:layout_constraintTop_toTopOf="#+id/tv_number"
app:layout_constraintHorizontal_bias="0"
style="#style/TextAppearance.Design.Tab"/>
</androidx.constraintlayout.widget.ConstraintLayout>`
It looks fine in android 22 and below but not android 24 and above. However before this migration to androidx it was fine in all versions i.e the indicator was at bottom of appbarlayout not inside it.
You must set app:tabIndicatorColor="YOUR_COLOR" in TabLayout like this:
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#color/blue">
... // Your TabItems
</com.google.android.material.tabs.TabLayout>
if doesn't work, try to remove android:layout="#layout/custom_tab" from TabItems too.

Floating action button are not aligned properly in Jelly bean (API 18), working fine 18 and above

I created layout with floating action button. There is one floating action button (called filter) by which i show up two other FABs.
Issue is about space between FABs. Gap is showing more in API level 18 and below.
Layout is working good in API level 19 and above but it is not showing properly in below 19, there is too much gap between floating action button, not sure what is issue here. Please let me know if i need spacial handling for 18 and below.
enter code here
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bottom_bar_color"
android:paddingTop="#dimen/activity_vertical_margin">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/pull_to_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.stylzq.widget.StylzQRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/images_data_list_frag_rv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/go_to_top_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="130dp"
android:layout_marginRight="15dp"
android:clickable="false"
android:src="#drawable/go_to_top"
android:visibility="gone"
app:backgroundTint="#color/colorPrimary"
app:borderWidth="0dp"
app:elevation="6dp"
app:layout_anchorGravity="bottom|right"
app:pressedTranslationZ="12dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="190dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ll_home_lyt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_6"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/fab_text_background"
android:padding="#dimen/dimen_3"
android:text=" Home "
android:textColor="#color/white"
android:textSize="16sp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_home_api"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginTop="#dimen/dimen_6"
android:layout_marginRight="16dp"
android:src="#drawable/ic_home"
app:backgroundTint="#color/colorPrimary"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</LinearLayout>
<LinearLayout
android:id="#+id/celebs_lyt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_6"
android:visibility="gone">
<TextView
android:id="#+id/celeb_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/fab_text_background"
android:padding="#dimen/dimen_3"
android:text=" Celebrity "
android:textColor="#color/white"
android:textSize="16sp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/celebs_api_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginRight="16dp"
android:src="#drawable/ic_celeb"
app:backgroundTint="#color/colorPrimary"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</LinearLayout>
<LinearLayout
android:id="#+id/popular_lyt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_6"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/fab_text_background"
android:padding="#dimen/dimen_3"
android:text=" Popular "
android:textColor="#color/white"
android:textSize="16sp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/popular_api_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginRight="16dp"
android:src="#drawable/ic_popular"
app:backgroundTint="#color/colorPrimary"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/api_filter_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="130dp"
android:layout_marginRight="16dp"
android:src="#drawable/ic_filter"
app:backgroundTint="#color/colorPrimary"
app:borderWidth="0dp"
app:elevation="6dp"
app:layout_anchorGravity="bottom|right"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</RelativeLayout>

Android avoid soft keyboard when startup

Below is a layout displaying a EditText at the top and a listview below it.
when the layout starts, the EditText will be in focus and the keyboard is open by default.
how can i avoid opening the keyboard until i touch the EditText intending to start typing?
thank you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/White"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="#string/title"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:gravity="center_vertical"
android:hint="#string/Search"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:selectAllOnFocus="true"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/Gray"
/>
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cacheColorHint="#android:color/transparent"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<Button
android:id="#+id/btn_add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Add"
android:onClick="onAdd"/>
</LinearLayout>
It would help . Just add a line in your manifest
<activity
android:name="com.example.activity"
android:windowSoftInputMode="stateHidden" // Add this to your manifest
android:label="#string/something">
</activity>

Resources