Sroll View Not Scrolling Up in Fragments Using the New Navigation Architecture Components - android-studio

I have a fragment that i have navigated to it using the modern Navigation UI. The problem am having is that the scroll view wont start scrolling unless the view is long. That's okay and i understand but it arises a problem where the Edit text inputs that are the bottom of the screen are being hidden when the keyboard is opened hence you can't see when you are keying in hence the reason for needing a scroll view to scroll down so that the view can be scrolled up above the keyboard
Is there a way to initiate the scroll view so that when the keyboard hides the Edit text input, i can still be able to scroll up and see what am keying in
My Navigation Host Fragment
<fragment
android:id="#+id/nav_host_fragment"
android:layout_below="#+id/app_bar_layout"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="#navigation/navigation_graph"
android:layout_above="#+id/bottom_nav"/>
My Fragment layout that has a scroll view and that its not scrolling
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.ScrollFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="5dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Second Name"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gender"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="country"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="province"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="County"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="province"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="region"
android:layout_margin="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="village"
android:layout_margin="5dp"/>
</LinearLayout>
</ScrollView>
If i add more view and the layout is long enough the scroll view is just working fine but its not scrolling when the views have not reached the bottom yet keyboard is hiding the view and i cant be able to see what am typing on the edit text
I have tried using Nested Scroll View and setting the
app:layout_behavior="#string/appbar_scrolling_view_behavior"
but its still not working.
I have also tried setting the following properties to the scroll view
android:isScrollContainer="false"
android:fitsSystemWindows="true"
android:fillViewport="true"

Related

Background and text colors interaction

I am trying to set background color in my application and print some text over it. It turns out that the default text color and the background color overlap each other if I am not setting the text color explicitly (see the picture below). Why is this happening? Is there any way to get rid of background transparency without setting the text color explicitly?
<?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"
android:layout_marginStart="30dp"
android:background="#ff00ff00"
android:clickable="true"
android:focusable="true"
tools:ignore="UnusedAttribute">
<RelativeLayout
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="120sp"
android:textColor="#ff000000"
android:text="text" />
<TextView
android:id="#+id/name2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/name"
android:textSize="120sp"
android:text="text" />
</RelativeLayout>
</RelativeLayout>
Actually the default color of texts is grey(*not black), so its the basic functionality of android system. If you want your text as Black color your have to mention it explicitly.
Else you can make a new style TextView(*Renderer) with default text color as black and use it everywhere.

Is there any typing option in android spinner?

As shown in the image, in Microsoft Word/Powerpoint the drop-down spinner of font size enables the users to type his own choice of font size in the spinner box in addition to manually selecting one from the drop-down list.
My question is if it is possible in Android to get the "self-typing" option likewise?
Here it is. I've solved it this way.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/background_light">
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"></Spinner>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="12"
android:inputType="numberDecimal"
android:gravity="center"/>
</FrameLayout>

how to center an image horizontal and vertical inside an edit text in android xml

Something like this please.
I'm new to android, and I am trying to center the image and hint both vertical and horizontal. If anyone can help, I will really appreciate it.
You can't put ImageView inside of an EditText.
You can, instead, put EditView and TextView inside RelativeLayout and center them, like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:text="This is some edit text" />
<ImageView
android:id="#+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/com_facebook_button_icon_blue" />
</RelativeLayout>
Since we put EditText width and height to match RelativeLayout, it would appear as if the ImageView is inside of an EditText.
If you want to put text under image just add this line to TextView: android:layout_below="#+id/my_image_view".

change text position to bottom left on screen rotate android

I have to display a text (id- text_view in the code below)at the bottom left of the screen. Find below the code snippet for the text.
<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal" >
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:text="SampleText"
android:textColor="#android:color/darker_gray" />
</FrameLayout>
<RelativeLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_marginBottom="14dip"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:layout_marginTop="14dip"
android:orientation="vertical" />
</RelativeLayout>
It is coming at bottom left but for only Portrait mode. When i rotate screen to landscape mode the text remains there, It should also be rotated to Bottom left of the screen.
Please help me how to achieve this on screen rotation
1:- First Change the FrameLayout to RelativeLayout.
2:- Set layout_gravity of textview to left|bottom.

scrollbar not showing in edittext

I am trying to add a box for entering text. This box should have a small scroll bar on the side. Using this piece of code, what I get is a blank line in which I can enter multiple lines of text. Would anyone know how I could get the box with a scrollbar?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_height="200dp"
android:layout_width="match_parent">
<EditText
android:id="#+id/event_description"
android:hint="#string/hint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#02960B"
android:textSize="14sp" />
</ScrollView>
EditText inside scrollview will not show you the scroll bar. To show scroll bar for edittext use the following code in yout EditText field for this you don't need to use scrollview you can get rid of it.
android:inputType="textMultiLine"
ScrollView can show scroll bar only if it contain more elements than its height size
A typical Exampl of EditText with scrollbar:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignLeft="#+id/search_query"
android:layout_alignParentBottom="true"
android:inputType="textMultiLine" >
</EditText>

Resources