I am new to android development please help me in creating this type design
I want to add text in the center of the top borders in the card
please help me or guide me to achive the same view
in TextView
android:hint="#string/name"
Example
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/editTextLayout"
style="#style/Widget.Material3.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="none"
android:hint="#string/name"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
Take a look at he reference code available here
CountDownTimerView
Make changes according to your need.
Happy Codingđ
<RelativeLayout
android:layout_width="300dp"
android:layout_height="100dp"
android:background="#drawable/bg_border_offer"
>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Offer ends in"
android:layout_centerHorizontal="true"
android:background="#drawable/bg_white"
android:textColor="#color/black_text_color"
android:layout_marginTop="-8dp"
/>
</RelativeLayout>
Related
I am trying to create an animated TextInput layout for my login page but I cant't make it work.
below are the pictures of what I am trying to do:
image when you arrive on the login page:
when you start typing the email, the line length should decrease when email address is typed, the more you type the smaller the line became.
Here is the layout I have created but it's not working.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/email_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#color/transparent"
android:textAllCaps="true"
android:textColorHint="#color/gainsboro_00"
android:textColor="#color/gainsboro_00"
android:hint="#string/email">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/transparent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/email_et"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:inputType="textEmailAddress"
android:textColor="#color/gainsboro_00"
android:background="#color/transparent"
android:minWidth="75dp"
android:textSize="14sp"
android:textAllCaps="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<View
android:id="#+id/email_line"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#drawable/checkered_gainsboro_background"
android:layout_marginEnd="45dp"
app:layout_constraintStart_toEndOf="#id/email_et"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.textfield.TextInputLayout>
Any idea how to achieve this? I think I am not far from the solution
Thanks
You don't need ConstraintLayout and View elements inside TextInputLayout.
Documentation is here: https://material.io/components/text-fields/android#using-text-fields
Material Design provides you instant EditText with Animation. You simply need to change the style of the TextInputLayout as shown below in the code.
Here is the code you can use as per your requirements.
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/enter_your_email_id"
app:endIconMode="clear_text"
android:id="#+id/edtEmailID"
android:background="#color/colorWhite"
android:layout_below="#id/welcomeText"
app:endIconTint="#000"
android:layout_marginTop="25dp"
app:errorEnabled="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
app:hintTextColor="#000">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editEmailIn"
android:inputType="text"
android:background="#color/colorWhite"
android:textColor="#000" />
</com.google.android.material.textfield.TextInputLayout>
Refer to Documentation for better exposure
I have some trouble with a TextInputEditText and his hint message if I use the last material library version com.google.android.material:material:1.2.0-alpha02 .. I set 5 lines scrollable textInputEditText and I want to show the hint message align to top margin of that text input. On layout editor appears in the correct position, but when I run the app the position is vertical centered. Why ?
Instead i'm not encounter this problem with com.google.android.material:material:1.1.0-beta02
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/sendMailContainer"
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="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/popupTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/sendBusinessCard"
android:textColor="#android:color/black"
android:textSize="22sp" />
<TextView
android:id="#+id/subTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/sendBusinessCard"
android:textColor="#android:color/black"
android:textSize="18sp"
android:layout_below="#+id/popupTitle"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="20dp"/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/noteMessageContainer"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/subTitle"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="10dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/noteMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/emailText"
android:inputType="text|textMultiLine|textCapSentences"
android:textColor="#android:color/black"
android:textColorHint="#color/gray9B"
android:textSize="16sp"
android:isScrollContainer="true"
android:scrollbars="vertical"
android:textIsSelectable="true"
android:minLines="5"
android:maxLines="5"
android:gravity="top"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/notePopupLeftButton"
android:layout_width="180dp"
android:layout_height="35dp"
android:layout_alignParentStart="true"
android:layout_below="#+id/noteMessageContainer"
android:layout_marginBottom="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="40dp"
android:background="#FF515151"
android:text="#string/Cancel"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
<Button
android:id="#+id/notePopupRightButton"
android:layout_width="180dp"
android:layout_height="35dp"
android:layout_alignParentEnd="true"
android:layout_below="#+id/noteMessageContainer"
android:layout_marginBottom="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="40dp"
android:background="#FF515151"
android:text="#string/Send"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
And this is two screenshot, one of the layout editor with hint in correct position and other is an app screenshot:
enter code here
You can use
android:gravity="top|start"
property in your EditText of the address block and it shall act as the container's underlying controlling property and take the hint to top left corner.
Add android:gravity="top|start" to the EditText in the layout XML file.
Add this code in your EditText / TextInputEditText:
android:gravity="top|start"
I faced the same problem.
I tried to remove the inputType attribute
and the height of edit text becomes now dependent on the lines attribute.
Then my problem is solved
I have read in a blog entry that in ConstraintLayout 2.0.0, a way was introduced to create a flow of views. What I exactly want to achieve:
I have several TextViews with a fixed size next to each other. Depending on screen size, some TextViews should be pushed into the next line.
Example on big screen with six TextViews:
[AAA] [BBB] [CCC] [DDD]
[EEE] [FFF]
Example on small screen with six TextViews:
[AAA] [BBB]
[CCC] [DDD]
[EEE] [FFF]
I already saw this Stackoverflow question proposing to use a FlexboxLayout, but there is a comment saying that the same thing now can be achieved using ConstraintLayout.
Anybody can give me an example on how to achieve the desired behavior using ConstraintLayout? I was not able to find any instructions about this. Thanks in advance.
You can achieve this by adding a androidx.constraintlayout.helper.widget.Flow virtual view inside the androidx.constraintlayout.widget.ConstraintLayout and by referencing all your textviews with app:constraint_referenced_ids attribute.
Example below shows how I've achieved it.
<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"
android:orientation="vertical">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[AAAAAAAA]"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[BBBBBBBB]"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[CCCCCCCC]"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[DDDDDDDD]"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[EEEEEEEE]"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/text6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[FFFFFFFF]"
tools:ignore="MissingConstraints" />
<androidx.constraintlayout.helper.widget.Flow
android:id="#+id/flow1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dp"
app:constraint_referenced_ids="text1,text2,text3,text4,text5,text6"
app:flow_horizontalBias="0"
app:flow_horizontalGap="10dp"
app:flow_horizontalStyle="packed"
app:flow_verticalBias="0"
app:flow_wrapMode="chain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Play around with app:flow_ attributes to change the arrangement of the textviews such as alignment, margin, etc.
https://developer.android.com/reference/androidx/constraintlayout/helper/widget/Flow
Final result should look like below depending on your screen size.
I want go design chip layout like below.
When Text is short enough to fit withing the layout I want to view like this.
When Text is too long to fit in I want it display like this and animate text horizontally.
Is it possible to design a layout that fulfill both about needs.
I have tried solution and i have filed because those layout designs only fulfill one condition.
Solution one
<RelativeLayout
android:id="#+id/relative_store_name_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="10dp"
android:layout_weight="9"
android:visibility="visible">
<FrameLayout
android:id="#+id/relative_shop_name_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/relative_shop_name_text"
android:layout_width="wrap_content"
android:layout_height="21dp"
android:background="#drawable/selected_store_name_text_background"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingStart="10dp"
android:ellipsize="marquee"
android:text="" />
</FrameLayout>
<FrameLayout
android:id="#+id/relative_layout_delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_toEndOf="#id/relative_shop_name_container">
<ImageView
android:layout_width="wrap_content"
android:layout_height="21dp"
android:background="#drawable/selected_store_name_delete_background"
android:paddingEnd="5dp"
android:paddingStart="10dp"
android:src="#drawable/store_name_chip_delete" />
</FrameLayout>
</RelativeLayout>
Problem with this is when text is too long delete button disappears. this layout on work for short text.
Solution two
<LinearLayout
android:id="#+id/store_name_liner_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="10dp"
android:layout_weight="9"
android:orientation="horizontal"
android:visibility="visible"
>
<LinearLayout
android:id="#+id/liner_shop_name_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="9">
<TextView
android:id="#+id/liner_shop_name_text"
android:layout_width="wrap_content"
android:layout_height="21dp"
android:background="#drawable/selected_store_name_text_background"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingStart="10dp"
android:text="short Text" />
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="21dp"
android:background="#drawable/selected_store_name_delete_background"
android:paddingEnd="5dp"
android:paddingStart="10dp"
android:src="#drawable/store_name_chip_delete"
/>
</FrameLayout>
</LinearLayout>
Problem with this is when text is short delete button is not going to fit just after text. I can't make that happen by removing weight from both text view container and delete image view container but then I get the same problem in my solution one.
Please give solution to handle this.
You need to make a custom view. That way you can measure the text and resize to fit.
Just add ellipsize="end" to your chip
Just add **ellipsize="end"** to your chip
<com.google.android.material.chip.Chip
<-- android:ellipsize="end" -->
/>
How do I display a TextArea for my android project? From xml, the only choice is TextField, multi lined. But thats editable. I need a TextArea which is only for displaying messages/text can't be edit/input by the user.
Try this:
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="150dp"
android:inputType="text|textMultiLine"
android:gravity="top"/>
Use TextView inside a ScrollView
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="150dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
If you do not want to allow user to enter text TextView is the best option here. Any how you can also add EditText for this purpose. here is a sample code for that.
This would automatically show scrollbar if there is more text than the specified lines.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="8"
android:maxLines="10"
android:minLines="6"
android:scrollbars="vertical" />
Edit: Adding attributes below to textView would make it a textArea that would not be editable.
android:lines="8"
android:maxLines="10"
android:minLines="6" // optional
Its really simple, write this code in XML:
<EditText
android:id="#+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="First Name"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="160dp"
android:ems="10"
android:gravity="left|top"
android:hint="Write your comment.."
android:inputType="textMultiLine"
android:textSize="15sp">
<requestFocus />
</EditText>
Use TextView inside a ScrollView to display messages with any no.of lines. User can't edit the text in this view as in EditText.
I think this is good for your requirement. Try it once.
You can change the default color and text size in XML file only if you want to fix them as below:
<TextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="100px"
android:textColor="#f00"
android:textSize="25px"
android:typeface="serif"
android:textStyle="italic"/>
or if you want to change dynamically whenever you want use as below:
TextView textarea = (TextView)findViewById(R.id.tv); // tv is id in XML file for TextView
textarea.setTextSize(20);
textarea.setTextColor(Color.rgb(0xff, 0, 0));
textarea.setTypeface(Typeface.SERIF, Typeface.ITALIC);
<EditText
android:id="#+id/comments_textbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="comments"
android:inputType="textMultiLine"
android:longClickable="false" />
use it to create multi line text box like textArea in Html
Defining an Android Mulitline EditText Field is done via the inputType=âtextMultilineâ. Unfortunately the text looks strangely aligned. To solve that also use the gravity=âleft|topâ attribute.
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:gravity="left|top"
android:inputType="textMultiLine" >
<requestFocus />
check this vogella blog
All of the answers are good but not complete. Use this.
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:background="#drawable/text_area_background"
android:gravity="start|top"
android:hint="#string/write_your_comments"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:padding="12dp" />
this short answer might help someone who is looking to do.
add this simple code in your code
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:focusable="false"
android:singleLine="true" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="100dp">
<EditText
android:id="#+id/question_input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:inputType="text|textMultiLine"
android:lineSpacingExtra="5sp"
android:padding="5dp"
android:textAlignment="textEnd"
android:typeface="normal" />
</android.support.v4.widget.NestedScrollView>
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/border_layout"
android:inputType="text|textMultiLine"
android:gravity="top"/>
Create a Drawable Resource file called border_layout
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#color/custom_grey" />
</shape>
custom grey color under values->colors.xml
<color name="custom_grey">#494646</color>