The letters do not look exactly in Edittext
click here for screenshot
<EditText
android:id="#+id/txtsearch"
android:layout_width="match_parent"
android:layout_height="43dp"
android:gravity="bottom"
android:hint="Ara"
android:layout_gravity="bottom|right"
android:background="#drawable/border"
android:textColor="#color/siyah" />
border.xml :
android:shape="rectangle">
<corners
android:radius="5dp"
/>
<solid android:color="#ffffff"
/>
<stroke
android:width="3dip"
android:color="#8f1d1d" />
Remove this line from your <EditText> tag:
android:gravity="bottom"
and add these:
android:gravity="start|center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
This will position the text as follows:
Related
My EditText has a background that makes it round and with a stroke of 3dp, I am trying to have a permanent indent implemented so that the text doesn't start in the stroke of the background. All ive come across is android: paddingStart/paddingEnd and I can not seem to get it to work. Is there any other way of achieving this programmatically or no? I would want it about 1dp past the stroke or maybe 3dp but I can't find a way to achieve this.
xml
<EditText android:id="#+id/w_SearchBarFullScreen"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="355dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/web_search_bar"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
android:text=" "
android:elevation="5dp"
android:focusable="true"/>
background xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fff" />
<stroke
android:width="3dp"
android:color="#e0e0e0" />
<corners
android:radius="15dp"/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
Remove padding from background.xml
use paddingLeft="10dp"
in Edittext
Try this...
no need to set fixed height and width for edittext here.
.xml
<?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="com.silambarasan.test.MainActivity"
>
<EditText
android:id="#+id/w_SearchBarFullScreen"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:background="#drawable/web_search_bar"
android:elevation="5dp"
android:focusable="true"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
web_search_bar.xml (Drawable)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fff" />
<stroke
android:width="3dp"
android:color="#e0e0e0" />
<corners
android:radius="15dp"/>
<padding
android:left="15dp"
android:top="15dp"
android:right="15dp"
android:bottom="15dp" />
</shape>
Result:
The padding in the background was stopping me from doing this so in android:paddingLeft = 10dp is the correct not in the layoutXML file rather the background
This is perhaps a bit hard to explain, so I included a picture to show you what I mean.
I have three images in Android Studio. They should all be alined to match and the middle part should expand as the text on top of the graphic expands (the middle height should equal the text height I suppose). Have been sitting with this for awhile now but don't get anywhere.
Do I add code in xml? Something like android:layout_height="#id/textView"
Is it better to do relative constraints in xml or constraints in UI?
In xml, how do I do relative constraints to other children? I know code like android:layout_alignParentTop, android:layout_alignChildTop, but how do I set distance to children?
If I read this correctly, you want the centre image and text view to adjust height based on the height of the text. The simplest way of doing that would be using your middle image as a stretchable background to the text view and similarly for the header and footer views, preferably using 9-patch PNG images.
Solution 1: Using 9-patch PNG images
Here is an example XML with 9-patches to show how this works.
N.B. The example contains two layouts, each enclosing a single TextView with header and footer views. The first TextView has a single line of text, the second has two lines.
<LinearLayout
android:layout_width="320dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#drawable/top" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="32sp"
android:padding="5dp"
android:gravity="center_horizontal"
android:text="A line of text"
android:background="#drawable/middle" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#drawable/bottom" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:layout_width="320dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#drawable/top" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="32sp"
android:padding="5dp"
android:gravity="center_horizontal"
android:text="A line of text\nAnother line of text"
android:background="#drawable/middle" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#drawable/bottom" />
</LinearLayout>
Nine-Patches
top.9.png:
middle.9.png:
bottom.9.png:
Example output
Solution 2: All XML
Alternatively, you could do it all in XML using <shape> and <layer-list> drawables instead of the 9-patch PNG images. Here is a modified version of the above to work with XML drawables.
This example shows rounded corners on the border as an added bonus, but beware it can be tricky to draw complex compound shapes using XML as there are only a small number of primitive shapes you can use.
Note also that this version relies on the addition of dimension resources to ensure everything matches up.
res/values/dimens.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android" >
<dimen name="layout_width">320dp</dimen>
<dimen name="header_height">15dp</dimen>
<dimen name="header_inset_height">5dp</dimen>
<dimen name="inset">5dp</dimen>
<dimen name="inset_width">310dp</dimen>
<dimen name="footer_height">15dp</dimen>
<dimen name="corner_radius">10dp</dimen>
<dimen name="inset_radius">5dp</dimen>
</resources>
res/drawable-nodpi/header.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#ffff00ff" />
<corners
android:radius="#dimen/corner_radius"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp" />
<size
android:width="#dimen/layout_width"
android:height="#dimen/header_height" />
</shape>
</item>
<item
android:top="#dimen/inset"
android:left="#dimen/inset"
android:right="#dimen/inset">
<shape android:shape="rectangle">
<solid android:color="#ffffff00" />
<corners
android:radius="#dimen/inset_radius"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp" />
<size
android:width="#dimen/inset_width"
android:height="#dimen/header_inset_height" />
</shape>
</item>
</layer-list>
res/drawable-nodpi/body.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#ffff00ff" />
<size android:width="#dimen/layout_width"/>
</shape>
</item>
<item
android:left="#dimen/inset"
android:right="#dimen/inset">
<shape android:shape="rectangle">
<solid android:color="#ffffff00" />
<size android:width="#dimen/inset_width" />
</shape>
</item>
</layer-list>
res/drawable-nodpi/footer.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#ffff00ff" />
<corners
android:radius="#dimen/corner_radius"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<size
android:width="#dimen/layout_width"
android:height="#dimen/footer_height" />
</shape>
</item>
<item
android:bottom="#dimen/inset"
android:left="#dimen/inset"
android:right="#dimen/inset">
<shape android:shape="rectangle">
<solid android:color="#ffffff00" />
<corners
android:radius="#dimen/inset_radius"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<size
android:width="#dimen/inset_width"
android:height="#dimen/header_inset_height" />
</shape>
</item>
</layer-list>
res/layout/activity_main.xml:
<LinearLayout
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:gravity="center"
android:fitsSystemWindows="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="#dimen/layout_width"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="#dimen/header_height"
android:background="#drawable/header" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="32sp"
android:padding="5dp"
android:gravity="center_horizontal"
android:text="A line of text"
android:background="#drawable/body" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/footer_height"
android:background="#drawable/footer" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:layout_width="#dimen/layout_width"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="#dimen/header_height"
android:background="#drawable/header" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="32sp"
android:padding="5dp"
android:gravity="center_horizontal"
android:text="A line of text\nAnother line of text"
android:background="#drawable/body" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/footer_height"
android:background="#drawable/footer" />
</LinearLayout>
</LinearLayout>
Example output:
I'm looking into putting a border around my spinner. I've set up an XML file for it but it doesn't seem to work. I'm not sure what I'm doing wrong, I'm sure it's something simple as usual.
Activity_main.xml
<LinearLayout
android:id="#+id/layout_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="0dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/activity_main_time_iv"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_time_48dp" />
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="#+id/activity_main_time_spinner"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_padding"
android:background="#drawable/dropdown_border"
android:layout_marginTop="-5dp"
android:layout_marginBottom="-5dp"
android:spinnerMode="dialog"
app:ms_text_color="#android:color/white"
app:ms_background_color="#android:color/background_dark"
app:ms_dropdown_height="300dp"
/>
dropdown_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/white" />
<corners android:radius="6dip" />
<stroke
android:color="#color/white"
android:width="#dimen/one_dp" />
dropdown_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="6dip" />
<stroke
android:color="#000000"
android:width="1dp" />
</shape>
I have this xml where I already set stroke color but I sometimes I want to change stoke color programmatically. The file name is dummy.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff" />
<stroke
android:width="1dp"
android:color="#ff000000" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
I want to change color (stroke color) programmatically, how I can do this?
I use this xml here :
<LinearLayout
android:layout_marginTop="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/a"
android:layout_gravity="center"
android:background="#drawable/dummy"
android:layout_marginBottom="2sp"
android:orientation="horizontal"
android:padding="5dp">
<RelativeLayout
android:id="#+id/serverStatusWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:background="#drawable/shadow_green"
android:padding="2dp">
<ImageView
android:id="#+id/serverStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:antialias="true"
android:src="#drawable/ic_settings_input_antenna_white_24dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/locationStatusWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/shadow_red"
android:padding="2dp">
<ImageView
android:id="#+id/locationStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:antialias="true"
android:src="#drawable/ic_warning_white_24dp" />
</RelativeLayout>
</LinearLayout>
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.a);
You can change the stroke as
GradientDrawable drawable = (GradientDrawable)linearLayout.getBackground();
drawable.setStroke(3, Color.RED);
And can change solid color as
GradientDrawable drawable = (GradientDrawable)linearLayout.getBackground();
drawable.setColor(Color.RED);
Hope this helps
I get this error when viewing my app.
"The graphics preview in the layout editor may not be accurate:
Path.isConvex is not supported. (Ignore for this session)"
see picture of error:
Here are the widgets in the activity_main.xml
<ImageButton
android:id="#+id/ImageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/RoomEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"
android:background="#drawable/button_go"
android:minHeight="40dp"
android:minWidth="256dp" />
<EditText
android:id="#+id/RoomEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/ImageButton1"
android:layout_below="#+id/imageView1"
android:layout_marginTop="80dp"
android:background="#drawable/editbox_round"
android:ems="10"
android:gravity="center_vertical|center_horizontal"
android:inputType="text"
android:maxLength="15"
android:minHeight="32dp"
android:minWidth="256dp" />
Here are the drawables:
button_go.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:endColor="#cc1a22"
android:startColor="#550200" />
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" >
</corners>
</shape>
editbox_round.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#000000"
/>
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
/>
</shape>
I'm not exactly sure why they are showing up invisible. If someone would be as kind to show me what exactly is going on here?
You get "Path.isConvex is not supported" error because you get a radius value for each corner separately. You must use
<corners android:radius="10dip" />
instead of
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
/>
I'm not quite sure, but sometimes preview is not so accurate and may not be available. Try run on actual device or emulator to see if it visible or not.