Can't inflate custom background editText - java

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 ?

Related

How to change width of track for horizontal scrollbar?

I have got a horizontal recyclerView which use horizontal custom scrollbars but i have an issue, thumb is over than the track, how can i specify the width of track for scrollbar?
here is my RecyclerView:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/itemRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:scrollbars="horizontal"
app:layoutManager=".LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/skinName2"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarThumbHorizontal="#drawable/scrollbar_horizontal_thumb"
android:scrollbarTrackHorizontal="#drawable/scrollbar_horizontal_track"
tools:itemCount="15"
tools:listitem="#layout/item_item" />
Here is my custom thumb:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="center_vertical"
android:height="1dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>```
and here is my track
```<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="center_vertical"
android:height="1dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
issue is here
Any ideas?

How can I set the Spinner menu to DropDown instaed of dialog style?

I created a Spinner style file, because I'd like to have a nice looking spinner.
Now if I click on the spinner i don't get anymore the default dropdown menu, but a dialog, to select an item from the spinner. How can I change it back to dropdown?
XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/radiosection">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/headerkernlochrechner"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="162dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp" />
<Spinner
android:id="#+id/steigungsspinner"
style="#style/SpinnerTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView2"
android:layout_marginTop="62dp"
android:spinnerMode="dropdown" />
</RelativeLayout>
The Spinner Style:
<style name="SpinnerTheme" parent="android:Widget.Spinner">
<item name="android:background">#drawable/bg_spinner</item>
</style>
And the Spinner Style Background:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<gradient android:angle="90" android:endColor="#ffffff" android:startColor="#ffffff" android:type="linear" />
<stroke android:width="0.33dp" android:color="#0fb1fa" />
<corners android:radius="0dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item android:right="5dp">
<bitmap android:gravity="center_vertical|right" android:src="#android:drawable/arrow_down_float" />
</item>
</layer-list>
</item>
</selector>
Thank you for help :D
Now I find a answer:
I had to add in the XML of the spinner the line:
android:spinnerMode="dropdown"
Now it works!

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>

Android – MapFragment overlay button shadow, just like MyLocation button

I'm struggling to add a shadow to my custom overlay button over the google map. My goal is to make my custom button look just like Google's MyLocation button. Here's how my app looks like now:
layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
style="#style/AppTheme">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_search_black_24dp"
android:tint="#color/icon_gray"
android:onClick="searchButtonClicked"
android:background="#drawable/mapbutton"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.quinny898.library.persistentsearch.SearchBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchbox"
/>
</LinearLayout>
</RelativeLayout>
mapbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#55FFFFFF" />
</shape>
</item>
<item
android:state_pressed="true"
android:state_enabled="true">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#ccb3b3b3" />
</shape>
</item>
<item
android:state_focused="true"
android:state_enabled="true">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#A9FFFFFF" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:shape="rectangle">
<corners android:radius="1.3dp" />
<solid android:color="#baffffff" />
</shape>
</item>
</selector>
I have already tried changing the android:elevation value on the ImageButton. Unfortunately, adding elevation value doesn't seem to add a shadow to the button. Is there a way to add a shadow to my mapbutton drawable?
From here what worked for me was:
<ImageButton
android:clipToPadding="false"
android:outlineProvider="bounds"
android:elevation="2dp" />
Try this code
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:left="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp"/>
<solid android:color="#D6D6D6"/>
</shape>
</item>
<item android:bottom="2dp" android:right="2dp">
<shape>
<gradient android:angle="270" android:endColor="#DC5F0A" android:startColor="#E68F54"/>
<!--
<stroke android:width="1dp" android:color="#BABABA" />
-->
<corners android:radius="4dp"/>
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
I hope it will.

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