How do i get the button styles of the standard next/previous buttons and the gradient backgrounds like in the image below
gradient backgrounds like in the image below
Hi, for gradient backgrounds you can apply below Background Drawable code.
Change color codes according to your needs !
Create gradientbg.xml and paste code given below,
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#817f81"
android:endColor="#ccc9cc"
android:angle="90" />
</shape>
this will make gradient background that you need !
Thanks.
Got it.. extracted both from the AccountsAndSyncSettings.apk :) Its part of the Android system, so i guess there shouldn't be any copyright issues right?
You can add the image to the button using android:drawableRight attribute of <Button>
Related
After the call of EditText.setBackgroundColor(Color.RED) I see only a red rectangle with text inside it, but I want to change only the text background and to keep the standard bottom border which is grey when the field has no focus and blue if it has focus. Can I do it programmatically?
I want to change the text background to red if the input is invalid and to transparent if it is valid.
I think the best way is to work with drawable/shape.xml as background and upon logic code situation call EditText.setBackground(some_other_shape.xml). Here is an example for shape file xml demonstrating how to use:
Border color ("stroke"): In this example some custom color from colors.xml
Fill color ("solid"): In this example Android default transparent color
Even image icon inside
<!--Example for custom shape file xml design-->
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#mipmap/icon_image" />
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke android:width="1dp" android:color="#color/orange_primary" />
</shape>
</item>
</layer-list>
So just prepare several shapes for each situation you need. Another approach is to work with layout params etc. but I think this one is faster and gives more control for custom design in easy to understand code.
I have two buttons, one of them has default style, another has custom background drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="#color/green" />
</shape>
In the end buttons look like this:
So default button is somehow smaller than button with custom background, though they have same properties:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_button_rounded_green"
android:text="Positive"
android:textColor="#color/white"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Negative"/>
It seems that custom background changes minHeight. How can I make this buttons look the same?
btn_default_normal.9.png is the default Image set to default Button widget in Android from any specific platform. Find this file in you SDK installation and copy to your res folder.
Path to find android-sdk\platforms\android-APILEVEL\data\res
Default button have default 9-patch background with own margins, shadows, etc (different for different Android versions). You have to use custom background for both buttons or take one of the default 9-patch background and create similar bg for positive button.
The default Holo Android button graphic is a PNG which purposely contains padding. If you press and hold, you'll notice a glow around the button appears...which takes up that spacing.
The default 9 patch image for the button uses drawable padding. In order to mimic it in your own drawable you can use insets. Something like:
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/bg_button_rounded_green" android:insetBottom="10dip"
android:insetLeft="10dip" android:insetRight="10dip" android:insetTop="10dip" />
I'll let you figure out what the values should be.
I was trying to apply shadow effect for my views and find out that I could use gradient to do it.
I created an XML file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#android:color/transparent"
android:centerColor="#android:color/transparent"
android:startColor="#android:color/black"
android:angle="135"/>
</shape>
This works fine, but I needed to make it more like a shadow.
What I need is to remove the transition effect in gradient because I only need two colors in one view applied diagonally. How to do it?
If you want that to be something like tha background of your views, why don't you just save a B/W .jpeg or .png image inside your Drawables and use it when needed specifying its dimensions and alpha (opacity) parameter?
In that case I'd suggest using nine-patch drawables
in my current project I'm building an App with API 10 which should look like an ICS App.
Since my GUI is not very complex I can build this all manually, but I have some problems with button states.
I googled a lot and found nothing that would work for me so I would appreciate any help ;)
I designed an action bar with google ICS stock icons. When for example someone touches the search-loupe-icon, which has an 8dp padding around it, it's background color should change to a defined highlight-color-value.
So now you would suggest probably a selector drawable. But my case is: I have an icon-drawable which has an background-color, which I want to change. I dont want to change the icon, so since I cant change the backgroundcolor from a selector-xml this doesn't work.
(I thought I can setup multiple drawable-xml with my icon static bg colors so that I could refer with one selector to those different colored icons, but since a shape-drawable-xml cannot have a source and an bitmap-drawable-xml cannot have a background color, this is no sollution.)
If I try to change the background color in my onclick-listener (also tried onTouch) with:
ImageButton searchIcon = (ImageButton) findViewById(R.id.upper_actionbar_icon_search);
searchIcon.setBackgroundColor(R.color.android_ics_blue_light);
The Icon gets a dark grey bg color. This is also true for any other color altough nothing lies on top of the ImageButton. I also tried an ImageView.
So could someone explain to my please how the hell I can define a highlighted bg color-image without any hacks (default-gone image that lies above the icon and is set visible onclick).
Thanks so much!!
Okay the solution is simple.
Write yourself a drawable selector which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#color/android_ics_blue_light"/>
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#color/android_ics_blue_light"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/light_grey"/>
</shape>
</item>
Within your ImageButton code define your icon as src and your new drawable as background, like this:
<ImageButton
<!-- ... -->
android:src="#drawable/icon_search"
android:background="#drawable/actionbar_ontouch"
/>
Works like a charm!
is there any possible way to set the border around the TextView such like the pics shown below?
the first pic is what i currently got and the second one is what kind of border i want.
all element that contain in the LinearLayout are just indiviual textViews
thx so much for the help~~
You can do that by setting your TextView background a xml shape that has background and border like this:
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#191919" />
<stroke android:width="1dp" android:color="#191919"/>
</shape>
You can red more about this here
I think you can do that please check the following link: Android - Way to appear bordered text on the TextView? this might help to solve u r problem.