How to make Edittext content scrollable when not in focus? - java

How to make EditText content in android scrollable when not in focus . I want to scroll the content inside the editText . Below is the snippet of my xml
<EditText
android:id="#+id/item_desc_et"
android:layout_width="0dp"
android:layout_height="#dimen/_40sdp"
android:inputType="textMultiLine"
android:maxLines="100"
android:hint="enter description here"
android:imeOptions="flagNoExtractUi"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="start"
android:textColor="#color/colorBlack"
android:background="#drawable/rectangular_shape"
android:textSize="#dimen/_6ssp"
android:textAlignment="viewStart"
android:paddingStart="#dimen/_4sdp"
android:paddingEnd="#dimen/_4sdp"
app:layout_constraintTop_toBottomOf="#id/item_description_label"
app:layout_constraintStart_toStartOf="#id/item_description_label"
app:layout_constraintEnd_toEndOf="#id/btnSubmit"
/>

Related

How do I align the text in the text-area on bottom?

I want to align the text of this two labels on it's bottom, so the two values are aligned on the same height.
Sadly, I dont find an option like aligning it inside its own area.
gravity wont work. It has to be in xml.
Thank you!
<TextView
android:id="#+id/feed_euro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="#+id/feed_cent"
android:height="35dp"
android:text="23"
android:textColor="#color/colorTextBlack"
android:textSize="25dp" />
<TextView
android:id="#+id/feed_cent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:height="35dp"
android:text=",39 €"
android:textAlignment="textStart"
android:textColor="#color/colorTextBlack" />
If you want to set your textview text bottom
android:gravity="bottom"
or
if you want to set your whole component bottom
android:layout_gravity="bottom"
To align the text inside a TextView to its bottom, you can use
android:gravity="bottom"
(inside TextView tags)
You can change the gravity to bottom like below.
<TextView
android:id="#+id/feed_euro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="#+id/feed_cent"
android:height="35dp"
android:text="23"
android:textColor="#color/colorTextBlack"
android:textSize="25dp" />
<TextView
android:id="#+id/feed_cent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:height="35dp"
android:text=",39 €"
android:gravity="bottom"
android:textAlignment="textStart"
android:textColor="#color/colorTextBlack" />
And also you can try android:gravity="bottom" to the layout you have used to hold the both TextView and change the 2nd TextView height into wrap_content.
Hope you got the answer.

Radio buttons aligned with button on right & text on left

How to make radio buttons in the radio group in the same alignment and put button in the right and text in the left on Android?
I want to make a radio group with radio buttons. I want to do it like this
My code does it like this:
How can I adjust the alignment of all the radio bottoms and how can I put the button on the right and text on the left?
I do it by padding
Here is my code:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_horizontal"
android:gravity="center|center_horizontal|center_vertical">
<RadioButton
android:id="#+id/ÅlandIslands"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Åland Islands" />
<RadioButton
android:id="#+id/Albania"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Albania" />
<RadioButton
android:id="#+id/Algeria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Algeria" />
<RadioButton
android:id="#+id/AmericanSamoa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="American Samoa" />
<RadioButton
android:id="#+id/Andorra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingRight="250dp"
android:text="Andorra" />
</RadioGroup>
Your code is almost fine, You need to set each RadioButtons width to android:layout_width="match_parent" so your each radio button will occupy full width of its parent layout.
It would be much better if you use recycler view as it would be easier to maintain in case of data changes and you could also implement features like search and sort with it.

How to put gap for toggle image and hint text in Edittext android?

I am new for android. i want space gap between toggle image and hint text same field of edit text
.
This is my edit text xml code
<EditText
android:id="#+id/nation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/email"
android:layout_centerHorizontal="true"
android:drawableLeft="#drawable/ic_flag"
android:layout_marginTop="11dp"
android:inputType="textCapWords"
android:hint="Nationality"/>
use :
android:drawablePadding="20dp"
to change Hint text color use:
android:textColorHint="#android:color/darker_gray"
<EditText
android:id="#+id/nation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/email"
android:layout_centerHorizontal="true"
android:layout_marginTop="11dp"
android:drawableLeft="#drawable/ic_flag"
android:drawablePadding="20dp"
android:hint="Nationality"
android:textColorHint="#android:color/darker_gray"
android:inputType="textCapWords" />
Here is solution
I want space gap between toggle image and hint text same field of edit
text
set drawablePadding android:drawablePadding="15dp"
<EditText
android:id="#+id/nation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/email"
android:layout_centerHorizontal="true"
android:layout_marginTop="11dp"
android:drawableLeft="#drawable/ic_flag"
android:drawablePadding="15dp"
android:hint="Nationality"
android:inputType="textCapWords" />
in this edittext possible to decrease the hint text darkness
You can set hint color programmatically
editText.setHintTextColor(getResources().getColor(R.color.dark_gray));
use the drawablePadding property.
<EditText
android:drawablePadding="10dp"
android:id="#+id/nation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/email"
android:layout_centerHorizontal="true"
android:layout_marginTop="11dp"
android:drawableLeft="#drawable/ic_flag"
android:hint="Nationality"
android:inputType="textCapWords" />

How do I position the cursor at a default position?

The image shows the screenshot of my application. As you can see that the cursor is at the text field pertaining to "Height". Whenever I launch my app the default cursor position is at "Height". I want it to be on "Mass".
How do I do it ? I can't figure out. Please help.!
Take a look at your .xml file:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:ems="10" >
<requestFocus />
</EditText>
And set the <requestFocus /> tag appropriately.
Also, you can call:
EditText.requestFocus();
Either update your .xml file as follows.
<EditText
android:id=#+id/etMass
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<requestFocus/> </EditText>
Or Use Code:
EditText etMass = (EditText) findViewById(R.id.etMass);
etMass.requestFocus();

Android - Page heading Left-center alignment with Background

I have a problem with the page heading to be left-center of background irrespective of text size.
The text should be center of background irrespective of the text size.
I have used the following layout.xml for the textview:
<TableLayout
android:id="#+id/widget3d8"
android:layout_width="306dip"
android:layout_height="26dip"
android:gravity="fill_horizontal"
android:paddingRight="8px"
android:layout_x="5px"
android:layout_y="10px"
android:layout_weight="1"
android:background="#104082">
<TextView android:id="#+id/committeename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="100px"
android:paddingLeft="10px"
android:text=" "
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#ffffff"/>
</TableLayout>
Please help me how to make the text to be left-centered of the backgound irrespective of the text size. Thanks in advance.
I'd make the TextView have the same height as it's parent and set the gravity to vertically center the content.
<TextView android:id="#+id/committeename"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_x="0px"
android:layout_y="100px"
android:paddingLeft="10px"
android:text=" "
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#ffffff"/>
try
android:gravity="left|center_vertical"
Also set the textview to
android:layout_width="fill_parent"
android:layout_height="wrap_content"

Categories