Creating a Custom Compound Button Bar - android

I have to create a custom compound button bar control in Android like the one here. To create a button bar like this, I am thinking of extending a LinearLayout and add my buttons to it. The buttons have a black background but with a gradient fill; I am not keen on using PNGs since the color of the buttons can change at runtime.
How can I get similar effect in Android?
Thanks.

u have to use imageview as button.
set two image view you can change color the button
use xml file to src of that imageview like
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="#drawable/back_normal" />
<item android:state_pressed="true"
android:drawable="#drawable/back_pressed" />
</selector>
for gredient style.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="90" android:startColor="#663300"
android:centerColor="#330000"
android:endColor="#330000"/>
</shape>
thats it.

Related

How to create a custom navigation drawer selected item background in Android Studio?

I'm trying to achieve something similar to this image, where the selected navigation drawer item has a rounded rectangular background, but I can't seem to find the code that does this. This is from Android Studio's pre-made "Navigation Drawer" Activity.
For reference, here's what the default drawer selected item background looks like.
I tried creating a custom drawer_selected_item xml and drawer_item_bg xml, but I couldn't figure out how to adjust margins if I did it this way. The background width stretches across the entire drawer width, unlike the first image.
drawer_selected_item.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drawer_item_bg" android:state_checked="true" />
<item android:drawable="#android:color/transparent" />
</selector>
drawer_item_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/purple_200" />
<corners android:radius="45dp" />
</shape>

Add full active drop-shadow from figma for any icon

I want add drop-shadow in drawables for use them on any android icons (navbars, custom views, buttons). Then should get something like this. Trying with ninepatch and layer-list or just png. It works, but there is a problem: due to the shadow, paddings of drawable increases, as a result, main picture becomes smaller. And it becomes impossible to use such a layers-list in selector with other images for example. What can do about it?
Okay, I just used shadow png bitmap as background for vector image like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_vector_active_with_sunshine" android:state_checked="true" />
<item android:drawable="#drawable/ic_vector_inactive" android:state_checked="false" />
</selector>
Where ic_vector_active_with_sunshine:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drop_shadow" />
<item android:drawable="#drawable/ic_vector" />
</layer-list>

Android: How to create a customized edit text box like this?

I'm trying to create to make this form in Android
You see the EditText has some shadows at the front. How do I create that?
I created AutoComplete Text Views for State and Place. But how to I add that line and arrow on it?
You can set background drawable to achieve.either create custom drawable with shape or use background images and put it in the layout xml
android:background="#drawable/text_bg"
create an "testing_gradient.xml" file in /res/drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/grey">
<shape
android:shape="rectangle"
android:thickness="10dp"></shape>
</item>
<item
android:drawable="#color/white"
android:left="50dp">
<shape android:shape="rectangle"></shape>
</item>
</layer-list>
apply the code in layout xml file
<EditText
android:background="#drawable/testing_gradient"
android:layout_width="match_parent"
android:textColor="#color/black"
android:text="User input"
android:paddingLeft="60dp"
android:layout_height="60dp"/>
final result
Again, you can add more layer to input more images

How to change background of imageView on mouse over inside the Horizontal Scroll view

I have a horizontal scroll view. Inside this there is a LinearLayout which contains Images how can I change the background of Image when Mouse over of that image.
Use a selector for the background of your images like:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_hovered="true" android:drawable="#color/hovered_color"/>
<item android:drawable="#android:color/transparent"/>
</selector>
Note: only works on API 14 and up

Set radial gradient as window background

I have the following gradient_bg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:type="radial"
android:gradientRadius="200"
android:startColor="#666666"
android:endColor="#AAAAAA"
/>
</shape>
I would like to use this gradient as the android:windowBackground setting for my application. The application would then have a few views with transparent backgrounds on top of it.
I've tried applying this gradient directly using:
android:windowBackground="#drawable/gradient_bg"
within my application manifest, and then setting the scrollview background as transparent, but I just get the default black background.
How would I go about achieving this result? I specifically don't want to apply the background to the scrollview.
Thanks for your help in advance.
Another way might be to create a theme (in values/styles.xml):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="windowbg" parent="android:Theme">
<item name="android:windowBackground">#drawable/rectangle</item>
</style>
</resources>
Now you can add this theme to your activity/application like this:
android:theme="#style/windowbg"
Try making a bitmap from shape. So create antoher xml in which you relate to your shape. Some example:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background"
android:tileMode="repeat"/>

Categories

Resources