Android text input - field name shown in field itself - android-layout

I am trying to achieve a log-in screen like the following:
Where the field's name is displayed in the field itself. I am using the ADT plugin in Eclipse. I tried setting the android:text attribute of the text input, but I don't think this is correct because through the password field, only the dots show (the redacted text), and not the text itself. What is the attribute then. I have looked in the documentation for the EditText widget.
The XML I currently have for the two EditText fields are:
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/editText1" android:inputType="textEmailAddress" android:text="#string/username">
<requestFocus></requestFocus>
</EditText>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/editText2" android:inputType="textPassword" android:text="#string/password" ></EditText>

You should be able to set default values for the fields with android:hint or android:sethint I think its the first.
android:hint="Please enter your password"
its the first one, thanks to a search on SO. Just for additional info it came up with this.
SO Question about android:hint

Share Java code for when click on Submit Button then Show the Name
<EditText
android:id="#+id/name_enter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/Name"
android:inputType="textCapSentences|textAutoCorrect"
/>

Related

Layout in Android Emulator looks different as compared to the layout file

I have recently started learning Android Development. I am using Android Studio and I created the XML layout file with it. But the layout is looking different on the emulator to the one I created on XML and I have no clue why it is happening.
This is the picture of my Main activity layout:
And this is the picture of my emulator:
The plain text should be below the text view but in the emulator, its position is different(I have marked the error by red).
Here is the code for the Main activity:
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="208dp"
android:text="SUBMIT"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="80dp"
app:layout_constraintBottom_toTopOf="#+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:text="Enter the value in kg below"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
tools:layout_editor_absoluteX="100dp"
tools:layout_editor_absoluteY="73dp" />
I'm not sure why it is showing that way in the emulator versus the preview, but the reason that the EditText field isn't where you want it to be is because of how you have set the position of the editTextNumber field:
tools:layout_editor_absoluteX="100dp"
tools:layout_editor_absoluteY="73dp"
You are telling Android to position the field 100 pixels in and 73 pixels down from the top of the screen. Most than likely this occurred because you accidentally dragged the field slightly in the editor window, which specifies the exact pixel placement.
Instead, since you are using a ConstraintLayout, you'll want to set the location of the EditText in relation to other fields on your layout. For example, remove the two lines above and replace them with something like this:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
I would also suggest that you name your fields on the layout with descriptions of what they represent, rather than the defaults of textView and textView2. For example, consider changing textView2 to something like weight_label_textview. It will make it much easier to know which field you are dealing with both in the layout and in your code.
As you are using constraint layout every UI item must constraint vertical and horizontally. Try adding constraints to your EditText.

Android how to change text input background image

I have the following code for the input text
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/ic_login_screen_input_container">
<EditText android:id="#+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Name"/>
</android.support.design.widget.TextInputLayout>
After adding the android:background, the input text becomes:
As you see, i added the rounded container as a background image, but the input text box still has the rectangular box behind it. My ultimate goal is to create a input text box like this:
Then when user start typing in the box, the input text box should becomes:
Please let me know how i should achieve this
I resolve this problem by enabling Material Design as suggested by #Mohammad (https://stackoverflow.com/a/52401339/9793695), however, i also need to follow instruction in (Updating com.android.support libraries v7:26.+ to v7:28.0.0 throw Multiple dex files define Lcom/google/common/util/concurrent/ListenableFuture) to resolve all the dependencies first. Hope this help!
Use compileSdkVersion 28
Use targetSdkVersion 28
Dependencies
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:design:28.0.0-alpha3'
Add this code
<android.support.design.widget.TextInputLayout
android:id="#+id/userIDTextInputLayout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/userIDTextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email or Username" />
</android.support.design.widget.TextInputLayout>
add android:background="#drawable/ic_login_screen_input_container" inside EditText and remove it from TextInputLayout OR add android:background="#null" to your EditText

Focus is not working on top of card view

I created on date edit text, on click on that date dialog will open, and user can select the date and this should not be editable. We are using external key board for doing this action.
By using the key board focus is not coming to this edit text, but on touch this is working.
<android.support.design.widget.TextInputLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.eevoskos.robotoviews.widget.RobotoEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="#+id/etDate"
style="#style/EditTextStyle"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:singleLine="true"
android:hint="Date"
android:focusable="false"
android:textColor="#color/black"
android:textSize="21sp"
android:textStyle="bold"
app:typeface="condensed" />
</android.support.design.widget.TextInputLayout>
android:focusable="false"
if I make focusable as true, edit text will become editable which I don't want.
I had faced this problem a lot, For edit text you can use
edTimeTaken.setInputType(InputType.TYPE_NULL);
This does not let keyboard open.

i am using staggardGridView inside a scrollview with an image on top

i am using staggardGridView inside a scrollview with an image on top . i want to scroll the image and the list together. `
<FrameLayout
android:id="#+id/lighthouseFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/lightHouseImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
/>
</FrameLayout>
<com.origamilabs.library.views.StaggeredGridView
android:id="#+id/staggeredGridView2"
staggered:numColumns="2"
android:layout_below="#id/lighthouseFrameLayout"
staggered:drawSelectorOnTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
`
First of all if you are using a list view what ever it may be like grid or simple list. no need of scroll view. because in list view it automatically scrolls. coming to image with list then first add scrol view and in scroll view add image and list view. Hva eyou tried that!! Please have a look on this! project. If it helps you please cast a vote.

Android clickable layouts above empty views

My project also uses Xamarin with MvvmCross, but I don't think this will effect the answer since the problem is all view-layout/axml related.
I have a GridView that summarizes a list of contacts. When clicking on this grid view, I would like the user to be taken to another screen to add more contacts to this list (so there is more space).
Subscribing to the GridView's OnClick event gives me an exception, saying I should be subscribing to the item click event, so I have done this using a clickable relative layout that surrounds the GridView (and its accompanying empty image view) as such:
...
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/addContactsRelativeLayout"
android:clickable="true">
<ImageView
android:id="#+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_add" />
<Mvx.MvxGridView
android:id="#+id/addContactsGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Contacts"
local:MvxItemTemplate="#layout/contact_summary_item"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:columnWidth="55dip"
android:gravity="center" />
</RelativeLayout>
...
This works fine when the GridView is empty, and the empty ImageView is shown. However, when there are items in the GridView, the RelativeLayout no longer seems to exist and clicks over the GridView can be seen to highlight items on the GridView. This means the user is not taken to the screen to edit their contact list.
I have tried several different configurations and attributes from similar questions on SO, but I think the addition of an empty view is causing problems. Any help would be greatly appreciated.
Ok, after a lot more playing around I found a solution.
Essentially it's adding another relative layout, higher in the z-index and therefore above the 'real' contents, within the surrounding relative layout.
...
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView
android:id="#+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_add" />
<Mvx.MvxGridView
android:id="#+id/addContactsGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Contacts"
local:MvxItemTemplate="#layout/contact_summary_item"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:columnWidth="55dip"
android:gravity="center"
android:focusable="false"/>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:clickable="true"
android:id="#+id/addContactsRelativeLayout"/>
...
Then just move all your click listeners to listen to the relative layout at the bottom.

Resources