Why does button look weird? - java

I am trying to make a button like this:
That is how it shows up in my XML layout editor, and I want it to show like that in my emulator also. However, it looks like this in my actual emulator and test devices:
Why is it not rounded? How can I make it more rounded? Here is my button:
android:onClick = "messageButton"
android:text="Make Custom Message"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:layout_width="230dp"
android:layout_height="63dp"
android:background="#drawable/messagebutton"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:layout_above="#+id/helpbutton2"
android:layout_centerHorizontal="true" />
And here is the drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:topLeftRadius="100dp"
android:topRightRadius="100dp"
android:bottomLeftRadius="100dp"
android:bottomRightRadius="100dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="#A871A6"
android:startColor="#E8E8E8"
android:endColor="#33FF8B"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="250dp"
android:height="83dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape>
Thanks,
Ruchir

Rounded rectangle radius is considered like below image. What you need is to set radius to half of your button height which is 63/2=~32dp

Related

Drawable Layer always top

I don't know whether am wrong or not. I just want to add a box to my EmptyActivity in android studio. I create a resource file and access it from the Activity.xml file. But I found it always layered on top of any ImageView component.
image
Resouce file
page_select_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/white" />
<corners android:radius="10dp" />
</shape>
ActivityMain.xml
<ImageView
android:id="#+id/page_select_bar"
android:layout_width="409dp"
android:layout_height="70dp"
android:layout_marginTop="777dp"
android:contentDescription="#string/desc"
android:elevation="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="#drawable/page_select_bar"
tools:targetApi="lollipop" />
am I missing anything? I'm new to android :)
Try adding
<stroke android:color="#color/Black" android:width="2sp"/>
to your drawable inside <shape>
and use it as background

Can't inflate custom background editText

I'm trying to set background in my EditText.
I found and copy from internet this xml:
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:color="#028b53"
android:width="2.5dp" />
<corners android:radius="10dp" />
<gradient
android:type="linear"
android:angle="270"
android:startColor="#c3c3c3"
android:endColor="#FFFFFF" />
</shape>
and set this in EditText:
<EditText
android:id="#+id/etRandom"
android:layout_width="136dp"
android:layout_height="28dp"
android:layout_marginLeft="168dp"
android:layout_marginStart="168dp"
android:layout_marginTop="8dp"
android:background="#drawable/edittext"
android:ems="10"
android:inputType="textPersonName"
android:textColorLink="#android:color/black"
android:textSize="8sp"
app:layout_constraintBottom_toBottomOf="#+id/tRandom"
app:layout_constraintStart_toEndOf="#+id/tRandom"
app:layout_constraintTop_toTopOf="#+id/tRandom"
app:layout_constraintVertical_bias="0.761" />
now after run app I get crash:
drawable/edittext" (7f060054) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060054 a=-1 r=0x7f060054}
How to fix that ?

Q: Adding stroke to circular TextView on button click

I'm trying to implement my own color picker and I want to make stroke around the color when its clicked. But i have to do it programmatically which is difficult for me.. If someone can give me a hand that would be great
layout.xml
<TableRow style="#style/colour_palette_row">
<TextView
android:id="#+id/col_1"
style="#style/colour_palette_button"
android:background="#48ff00"
android:text="#string/number_one" />
<TextView
android:id="#+id/col_2"
style="#style/colour_palette_button"
android:background="#drawable/rounded_textview"
android:text="#string/number_two" />
<TextView
android:id="#+id/col_3"
style="#style/colour_palette_button"
android:text="#string/number_three" />
<TextView
android:id="#+id/col_4"
style="#style/colour_palette_button"
android:text="#string/number_four" />
<TextView
android:id="#+id/col_5"
style="#style/colour_palette_button"
android:text="#string/number_five" />
</TableRow>
drawable/rounded_textview.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/circle" />
</selector>
drawable/circle.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9FE554" />
<size
android:height="60dp"
android:width="60dp" />
</shape>
Also currently i'm using new file for each color if there are some suggestions about that it would be nice.

Putting border around a spinner

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>

Custom Button/EditBox are invisible?

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.

Categories

Resources