I want to set a text view and edit text on same line in android.
As I've wrote here I should do it with linear layout like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="200px"
android:orientation="horizontal"
android:layout_alignParentLeft="true"
android:background="#android:color/background_light"
android:layout_alignParentStart="true"
android:layout_below="#+id/loginTitle"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:text="Phone"
android:layout_height="200px"
android:gravity="center"
android:id="#+id/phoneTV"
android:textColor="#f7941e"
android:textSize="20sp">
</TextView>
<EditText android:layout_width="wrap_content"
android:id="#+id/phoneNumber"
android:layout_height="200px"
android:gravity="center"
android:background="#android:color/background_light"
android:text="0.00"
android:textSize="20sp"
android:inputType="number|numberDecimal"
android:layout_marginLeft="10dp">
</EditText>
</LinearLayout>
but it doesn't look at all as I want to.
My goal is to reach this component
Can you please help me how to do such a thing?
Thanks in advance!
Eden Ben simon
I put this together because I like its simple look.
Here is the final look of it.
layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2c2d2d"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="5dp"
android:background="#drawable/item_holder"
android:orientation="horizontal">
<TextView
android:id="#+id/phoneTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/item"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="Phone"
android:textColor="#f7941e"
android:textSize="16sp">
</TextView>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#bdbfc1"/>
<EditText
android:id="#+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/item_info"
android:gravity="left"
android:inputType="number|numberDecimal"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="516-678-7325"
android:textColor="#6d6e71"
android:textSize="16sp">
</EditText>
</LinearLayout>
</RelativeLayout>
Drawable Files Create three drawable files in the drawables folder. Used to create round corners.
item_holder.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke
android:width="1dp"
android:color="#b9bbbe"/>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:radius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
item.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="0dp"
android:radius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp"/>
</shape>
item_info.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#f1f1f2"/>
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="5dp"
android:radius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="5dp"/>
</shape>
Create a background for your TextView
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item android:right="-1dp">
<shape>
<solid android:color="#FFFFFF"/>
<stroke
android:width="1dp"
android:color="#BDBFC1"/>
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="0dp"
android:radius="1px"
android:topLeftRadius="7dp"
android:topRightRadius="0dp"/>
</shape>
</item>
</layer-list>
And your EditText
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item android:left="-1dp">
<shape>
<solid android:color="#F1F1F2"/>
<stroke
android:width="1dp"
android:color="#BDBFC1"/>
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="7dp"
android:radius="1px"
android:topLeftRadius="0dp"
android:topRightRadius="7dp"/>
</shape>
</item>
</layer-list>
Put this into your activity
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
>
<TextView
android:id="#+id/tvPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#drawable/text_view_background"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Phone"
android:textColor="#F7941E"
android:textSize="20sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/tvPhone"
android:layout_alignTop="#id/tvPhone"
android:layout_toRightOf="#id/tvPhone"
android:background="#drawable/edit_text_background"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textColor="#F7941E"/>
</RelativeLayout>
It looks like this, you just need to fine tune it a bit ;)
change the attribute in LinearLayout to android:orientation="vertical"
Change orientation to vertical and use layout_weight for both of your views.
Adjust the values to obtain the desired effect. More info here: Linear Layout
You can use drawable left attribute
android:drawableLeft="#drawable/name_icon_edittext"
Make separate image with text 'phone' and create an 9 patch image for Edittext background. I hope it will work !
Use dp instead px. It seems like a perfect place to just use a LinearLayout with orientation horizontal with a weights.
There is no need to write 200px every time just use Match parent.
So go with a LinearLayout with orientation: Horizontal unless I'm missing something here
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/bgmainactivity"
android:orientation="horizontal">
<TextView
android:id="#+id/phoneTV"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="0.5dp"
android:layout_weight="0.3"
android:background="#android:color/background_light"
android:gravity="center_vertical|center_horizontal"
android:padding="5dp"
android:text="Phone"
android:textColor="#f7941e"
android:textSize="20sp"
android:textStyle="bold"></TextView>
<!--U can use some like this to add divider -->
<!--<TextView-->
<!--android:layout_width="1dp"-->
<!--android:layout_height="match_parent"-->
<!--android:background="#android:color/background_dark"></TextView>-->
<EditText
android:id="#+id/phoneNumber"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="0.5dp"
android:layout_weight="0.8"
android:background="#EBEBEB"
android:gravity="center_vertical|center_horizontal"
android:inputType="number|numberDecimal"
android:padding="5dp"
android:text="0.00"
android:textSize="20sp"></EditText>
**bgmainactivity.Xml**
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#565656" />
<stroke
android:width="1dp"
android:color="#565656" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
I just hope remaining denting panting will done by your self.
Happy Coding
Related
I need to do this effect on a layout like the following :
I tried with gradient on a shape, shadows, https://developer.android.com/reference/android/graphics/drawable/NinePatchDrawable , https://developer.android.com/reference/android/graphics/BlurMaskFilter
or even some libraries: https://github.com/SanojPunchihewa/GlowButton
But it always depends on a bitmap or on a button
What I have for the moment is my drawable and layout :
Shape drawable with strokes :
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="22.5dp"/>
<padding android:left="3dp" android:right="3dp" android:top="3dp" android:bottom="3dp"/>
<stroke android:color="#color/colorAccent" android:width="1dp"/>
<solid android:color="#android:color/transparent"/>
</shape>
Layout :
<LinearLayout
android:id="#+id/text_selections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="#drawable/btn_rounded_accent_light_stroke"
android:gravity="center"
android:layout_gravity="center"
android:orientation="horizontal"
android:tag="perso_button_rounded_accent_light">
<TextView
android:id="#+id/text_selections_line_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:tag="perso_text_view_accent"
android:text="Ma Commande"
android:layout_marginRight="5dp"
android:textColor="#color/colorAccent"
android:textSize="17sp" />
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:text="5"
android:textColor="#color/colorBlueLight"
android:background="#drawable/bg_rounded_button"
android:shadowRadius="90">
</Button>
</LinearLayout>
The library is rendering like following which is pixelating
Do you have an idea on how to do this effect ? (I want to do it programmatically, not using an image)
Thanks in advance
I am getting a weird grey border around the input text field of a search view with emulators which have API >= 26. Only SearchViews inside of a fragment encounter this issue.
Can you please advise on how this can be resolved?
SearchView Picture
<?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:id="#+id/view_layout"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:background="#color/grey_background"
android:clickable="true"
android:focusableInTouchMode="true">
<RelativeLayout
android:id="#+id/search_view_layout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#color/grey_background">
<SearchView
android:id="#+id/search_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:iconifiedByDefault="false"
android:padding="2dp"
android:layout_margin="5dp"
android:layout_marginLeft="0dp"
android:queryHint="Search...."
android:elevation="0dp"
android:background="#drawable/search_view_border"
android:focusable="false"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycler_view"
android:paddingTop="5dp"
android:background="#color/grey_background"
android:layout_below="#+id/search_view_layout"
android:clickable="true"
android:focusableInTouchMode="true"
android:focusable="true" />
</RelativeLayout>
The code for search_view_border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<item>
<shape>
<!-- set the shadow color here -->
<stroke
android:width="10dp"
android:color="#A1A9B4" />
<!-- setting the thickness of shadow (positive value will give shadow on that side) -->
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="0dp"/>
</shape>
</item>
<!-- Background -->
<item>
<shape>
<solid android:color="#ffffff" />
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
try this idea
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="#drawable/border_shape_grey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_gravity="center"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="horizontal">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="#drawable/ic_search"/>
<EditText
style="#style/TextAppearance.AppCompat"
android:layout_width="0dp"
android:layout_weight="1"
android:hint="#string/action_search"
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants"
android:inputType="text"
android:singleLine="true"
android:background="#00000000"
android:padding="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
border_shap_grey.xml
<?xml version="1.0" encoding="utf-8"?>
<stroke android:width="2dp"
android:color="#f5f6f6"
/>
<solid android:color="#f5f6f6"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners
android:radius="5dip"/>
A solution to this issue that I have found:
Change the searchview widget to android.support.v7.widget.SearchView
Retrieve the search_plate layout and set its elevation to 0.
LinearLayout searchPlate = (LinearLayout) searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
searchPlate.setElevation(0f);
Reference:
Accepted answer in Changing the background drawable of the searchview widget
I'm trying to add a background rectangle shape to a custom RelativeLayout in android and I'm following the recommendations of most questions on here by implementing a custom drawable in customborder.xml and setting it as the background of the custom.axml view. I have also tried setting the relativeLayout source as well.
You can see I've also tried it in an imageView which isn't showing up either.
I've messed around with size and color but nothing appears to be rendered.
Am I missing something that needs to be done in code? Or the xml?
customborder.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
shape="rectangle">
<corners radius="20dp"/>
<padding left="50dp" right="50dp" top="50dp" bottom="50dp"/>
<stroke width="10dp" color="#B2F7FE"/>
<solid color="white"/>
</shape>
custom.axml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="#drawable/customborder">
<ImageView
android:id="#+id/imageViewBackground"
android:layout_width="fill_parent"
android:layout_height="49.0dp"
android:layout_gravity="center"
android:background="#ffededed"
android:adjustViewBounds="false"
android:alpha="1"
android:backgroundTint="#00000000"
android:foreground="#drawable/customborder" />
<refractored.controls.CircleImageView
android:id="#+id/Image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:src="#drawable/icon" />
<LinearLayout
android:id="#+id/Text"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="10dip"
android:layout_marginLeft="10.5dp"
android:background="#drawable/customborder">
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="24dip"
android:textColor="#FFFFFFFF"
android:paddingLeft="5dip"
android:text="Test"
android:layout_marginLeft="46.0dp"
android:layout_marginTop="12.0dp"
android:layout_gravity="left" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF7F3300"
android:textSize="20dip"
android:textStyle="italic" />
</LinearLayout>
Please replace your customborder.xml file with following code,
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
<padding
android:bottom="50dp"
android:left="50dp"
android:right="50dp"
android:top="50dp" />
<stroke android:width="10dp" android:color="#B2F7FE"/>
<solid android:color="#ffffff" />
</shape>
Your mistake was android prefix is missing.Also you are missing close tag in your layout.
Hi friends please help here i trying to do below shape more than three days but cant able to get it how can i do it
But the Output i am getting is this one
Below is my code
close_drawable.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#30000000"/>
<size android:height="70dp" android:width="70dp"/>
</shape>
<clip android:gravity="left" android:clipOrientation="horizontal"/>
</item>
<item android:drawable="#drawable/close" android:width="50dp" android:height="50dp" android:gravity="center"/>
</layer-list>
And my Xml Code is
<RelativeLayout
android:id="#+id/bottomroot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/nope"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/close_drawable" />
<ImageView
android:id="#+id/superlike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-1.5dp"
android:layout_toRightOf="#+id/nope"
app:srcCompat="#drawable/superlike_drawable" />
<ImageView
android:id="#+id/like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-1.5dp"
android:layout_toRightOf="#+id/superlike"
app:srcCompat="#drawable/like_drawable" />
<ImageView
android:id="#+id/like_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-1.5dp"
android:layout_toRightOf="#+id/like"
app:srcCompat="#drawable/likelist_drawable" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/superlike"
android:layout_alignEnd="#+id/superlike"
android:gravity="center"
android:layout_below="#+id/superlike"
android:text="Mashalla!"
android:textColor="#fff" />
</RelativeLayout>
Your circle xml shoul look like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<solid android:color="#20000000" />
<size
android:width="70dp"
android:height="70dp" />
</shape>
EDIT: this can happen if you have paddings in the layout that holds the ImageVIew
I use Buttons inside Linear Layout, Table Row and Table Layout, maybe this has some influence.
The problem is that state_pressed doesn't work properly. When I'm pressing Button A/B/C/D, Android is selecting Button D (it is slightly darker).
You can see on the image, that shadow works properly, but the background is setting always on the wrong button D (bottom right corner).
After clicking any button I change its background programmatically and set backgrounds to red or green. It works properly.
The red button is selecting, because our opponent selects this answer. It's setting programmatically and don't have any influence for my bug.
Here is my layout code
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rozgrywka"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/icon2"
android:background="#ffffffff"
android:padding="5dp"
android:weightSum="1">
<TableRow
android:layout_width="fill_parent"
android:layout_weight="0.5">
<LinearLayout
android:id="#+id/first"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/buttonA"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="1"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpA"
android:text="A"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
<Button
android:id="#+id/buttonC"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpC"
android:text="C"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_weight="0.5">
<LinearLayout
android:layout_height="fill_parent"
android:layout_alignStart="#id/first"
android:layout_weight="1"
android:id="#+id/second">
<Button
android:id="#+id/buttonB"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpB"
android:text="B"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
<Button
android:id="#+id/buttonD"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="1"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpD"
android:text="D"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
</LinearLayout>
</TableRow>
</TableLayout>
drawable rozgrywkabutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#c7c7c7" />
<gradient android:angle="-90" android:startColor="#d3ced3" android:endColor="#b6b2b6" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#5e7974" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#c7c7c7" />
<gradient android:angle="-90" android:startColor="#e4e4e4" android:endColor="#cbc7cb" />
</shape>
</item>
</selector>
I was using static function to make button default.
public static void setBacground(Button buttonA, Drawable draw) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
buttonA.setBackgroundDrawable( draw);
} else {
buttonA.setBackground( draw);
}
}
and in my function which make my button look default
Drawable defualt = getResources().getDrawable(R.drawable.rozgrywkabutton);
Global.setBacground(ButtonA, defualt);
Global.setBacground(ButtonB, defualt);
Global.setBacground(ButtonC, defualt);
Global.setBacground(ButtonD, defualt);
when i change this to
Global.setBacground(ButtonA, getResources().getDrawable(R.drawable.rozgrywkabutton));
Global.setBacground(ButtonB, getResources().getDrawable(R.drawable.rozgrywkabutton));
Global.setBacground(ButtonC, getResources().getDrawable(R.drawable.rozgrywkabutton));
Global.setBacground(ButtonD, getResources().getDrawable(R.drawable.rozgrywkabutton));
everything start work properly. Thanks for your time.