Rounded corners on layout - java

I want my GridLayout to have rounded corners like the 3 Buttons do in the below picture. Does this require code that is different for rounding corners of Views such as Buttons, TextViews, etc?
gameplayGL.setBackgroundResource(R.drawable.roundedcorners);
gameplayGL.setBackgroundColor(Color.BLUE);
gameplayGL.getBackground().setAlpha(35);
roundedcorners.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>

I'm pretty sure calling setBackgroundColor(Color.BLUE) overrides the setBackgroundResource() call.
Try making a different drawable resource that is this
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
<solid
android:color="#350000FF" />
</shape>
Then setting the background of the gridview to that. You may have to play with the color value to get exactly what you want.

Related

Android handle virtual Direction pad on screen to focus view

I'm developing an app can visible Direction pad on the screen, but I don't know how to handle or override action like UP, DOWN, LEFT, RIGHT to focus the next view (like some buttons in image below).
Set this tow attributes for your view items :
android:focusableInTouchMode="true"
android:background="#drawable/bg_view"
where bg_view.xml is :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<shape android:shape="rectangle">
<stroke android:width="2dp" android:color="#android:color/white" />
<solid android:color="#1F1F3E" />
</shape>
</item>
<item>
<shape>
<solid android:color="#1F1F3E" />
</shape>
</item>
I found a solution to what I need here Android simulate key press
. Use Instrumentation class to sendKeyEvent.

How to create a custom circular seekbar with custom thumb?

Im trying to create a custom circular seekbar like this one:
I have the shape and the thumb xml done but the thumb isn't appearing when i put it in the layout xml.
Seekbar background xml (lap_counter.xml):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle"
android:thicknessRatio="16"
android:useLevel="false">
<corners android:radius="500dp" />
<stroke
android:width="45dp"
android:color="#color/blue_secondary" />
</shape>
</item>
</layer-list>
Custom thumb xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/white">
<item>
<shape android:shape="oval">
<solid android:color="#color/white"/>
<stroke android:color="#color/orange" android:width="3dp"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
</item>
</layer-list>
But when apply the custom xml this are the results:
<androidx.appcompat.widget.AppCompatSeekBar
android:id="#+id/sb_lap_counter"
android:layout_width="700dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:progress="50"
android:background="#drawable/lap_counter"
android:thumb="#drawable/lap_counter_thumb"
tools:progress="50" />
I tried putting it in as a custom style in themes.xml but it doesn't work either.
What am i doing wrong?
You are using a seekbar.This only works for horizontal seeks.That orange thing is the thumbnail which you need.

Inner Shadow effect like Figma in native Android

I wonder if there is a way to create a view container with an Inner Shadow like in Figma in native Android.
I have already spent the whole day trying layer-list with different items (linear, radial gradients, shapes, bitmaps) but nothing seems to be similar to what I need.
Please check the attachment, pay attention to container's inner shadow, this is what I really need:
Links or parts of code/xml will be appreciated.
Thanks in advance!
Try this:
Example XML for the layer-list:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners android:radius="10dp"/>
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="10dp">
<shape android:shape="rectangle">
<solid android:color="#00000000"/>
<corners android:radius="10dp"/>
<padding
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="0dp"/>
</shape>
</item>
</layer-list>
You can set the above XML as the background for the CardView:
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/layer_list_example">
<!-- Add your content here -->
</androidx.cardview.widget.CardView>
Note that you may need to adjust the offset and blur radius to achieve the desired appearance.

LinearLayout with rounded corners and background color

CompileSdkVersion 26, if it's important. I want to create LinearLayout with rounded corners, and background color.
I created 2 LinearLayouts, one with corners, and one with color, but their shapes do not match my expectations.
Code from activity
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/whitegrey"
android:layout_marginTop="340dp"
android:id="#+id/layout"
android:layout_marginStart="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_border"
android:orientation="vertical"
android:padding="6dp"
android:textColor="#color/black">
...
</LinearLayout>
</LinearLayout>
custom_border.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
<stroke android:width="2dp" android:color="#444444" />
</shape>
Actually, there is rounded border, and behind, there is rectangular layout with target color. I want to fill with target color only what is inside borders.
Is there any way to set the fill color, preferably in custom_border.xml?
Here, what I have at the moment:
Here, what I want to achieve:
View from phone, the letters on the left are cut off:
From the code samples you provide us, it doesn't seem necessary to me to have two LinearLayout. Only the layout with android:background="#drawable/custom_border" is required.
To achieve the expected result, just add the property <solid android:color="#color/whitegrey" /> to your custom_border.xml :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
<stroke android:width="2dp" android:color="#444444" />
<solid android:color="#color/whitegrey" />
</shape>
I wish I was able to help you!

How to set the thickness of an EditText line?

I noticed that the two EditTexts I drew have different line thickness (the Password EditTexts line is thicker). Is there a property I can set so that they have the same thickness?
Thanks
You can handle it with a custom drawable
Add this drawable as a background of your edit text and you can can control it's width by changing width of stroke
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="10dp" />
<solid android:color="#00FFFFFF" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
</layer-list>

Categories

Resources