I m newly in android and making background with gradient from left to right on black to white.
I add reference image to make it.
If there is any suggestion, please add me.
For drawables , there is an attribute
android:autoMirrored="true"
..set this ..so when your app locale changes to an RTL support language..drawable will reflect that change
Please add below.
res/drawable/gradient_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="0"
android:endColor="#ffffff"
android:startColor="#000000" />
<corners
android:topLeftRadius="#dimen/button_radius"
android:topRightRadius="#dimen/button_radius"/>
</shape>
Explain:
angle
0 : from Left to Right
90 : Bottom to Top
180 : Right to Left
270 : Top to Bottom
corners
If you want to make the rounded background, add tag : corners
I think that you can use AnimationDrawable, the most basic way it's to have three color : blue, a gradient blue-yellow and yellow :
In res/drawable create a gradient.xml file (left to right):
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="0"
android:endColor="#FFFF00"
android:startColor="#0000FF" />
</shape>
Then in the same folder create a animalion-list.xml file :
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#0000FF" android:duration="333"/>
<item android:drawable="#drawable/gradient" android:duration="333"/>
<item android:drawable="#FFFF00" android:duration="333"/>
</animation-list>
Apply the animation-list as background to your relative layout :
<RelativeLayout:
android:...
android:...
android:drawable="#drawable/animation-list"
android:... >
...
</RelativeLayout>
Related
The line underneath the text is a drawable set to the background of the view and when editText.setBackgroundColor(color) is called the following happens internally:
setBackground(new ColorDrawable(color));
This removes the drawable that contained the line and replaces it with the color we gave it.
Is it possible to change the background color of an EditText without having the line under the text disappear?
Setting the EditText inside a layout and changing the layout's background color is not an option.
Try to make drawable some think like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-2dp" android:left="-2dp" android:right="-2dp">
<shape>
<solid android:color="#color/background_color"/>
<stroke android:color="#color/underline_color" android:width="2dp"/>
</shape>
</item>
</layer-list>
The set your EditText background from resources like this:
editText.setBackgroundResource(R.drawable.name_to_xml_file);
Hi I have a problem with my toolbar. I'm testing on a lollipop 5.1.1. I have tried:
How to add image in toolbar
This Setting header color of app in overview (recent apps) screen
takes the full width background image and squashes it into the icon.
The toolbar displays the correct background image when i am in the app (on Create or on Resume)
but if I am in on Pause, the default colorPrimary and mipmap icon show as below
I have tried all suggestions on Stackoverflow. I am beginning to think that truly one cannot customise the toolbar in taskView or the recent apps screen.
Does anyone know any unconventional way of having my background image in Task View (recent apps screen) and not the default colorPrimary with the default mipmap icon?
in onCreate, I tried doing the following as well:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
ActivityManager.TaskDescription td = new ActivityManager.TaskDescription("",bm,R.drawable.header);
setTaskDescription(td);
whereby header is a drawable xml file that has myImage in it:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/myImage" />
<item>
<shape android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
but get a crash with the warning that the primaryColor must be opaque.
I have a custom button shape that I am using for all of my buttons. I am trying to implement themes now but I can figure out how to automatically change the "solid" color of the buttons without getting rid of my custom shape. Can anyone let me know how to go about this? I've attempted to change the background colour of the button but I don't see any change; not sure why.
Here's my custom button shape:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<solid
android:color="#D1D1D1"
/>
<size
android:width="177dp"
android:height="60dp"
/>
<stroke
android:width="7dp"
android:color="#FFFFFF"
/>
</shape>
I think you should assign an id to the xml file
then you just make recognize the Button by mean of findViewById
In the case you use multiple themes, you could use a case switch functionality
Button button= (Button)findViewById(R.id.yourbutton)
button.setBackgroundColor(getResources().getColor(R.color.whatevercolor)); //or even better button.setBackgroundColor(0xFFFFFF);
I've already posted a related question but was partially solved, so here I'll show you the whole code.
The problem is that I can't set a background from a RelativeLayout in white, for example, and set simultaneously, by java code, a background resource (.PNG file) and merge them.
The .PNG image is a prototype of part of the game screen and has transparent space. What I want to obtain is to show this background in white, because of there are details in black that can't be seen because my pre-established background is black (initial theme selected I suppose).
The code below corresponds to the XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/id_act_principal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:keepScreenOn="true"
tools:context=".Principal" >
And the .java file:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
RelativeLayout fondo = (RelativeLayout) findViewById(R.id.id_act_principal);
fondo.setBackgroundResource(R.drawable.prototipoestructurapantalla);
}
The .java file sets the background image correctly, but in the XML file is set to show the white background and it doesn't show it. It keeps being black.
I hope you can help me.
Try this:
Create a drawable named image_with_white_backgroud.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape >
<solid android:color="#android:color/white"/>
</shape>
</item>
<item>
<bitmap
android:src="#drawable/prototipoestructurapantalla"/>
</item>
</layer-list>
In your RelativeLayout replace android:background="#android:color/white" with android:background="#drawable/image_with_white_backgroud"
you can only have one background at a time, try leaving the relativelayout as it is, and insert an ImageView for the png.
I'm developing an app and when I run it in the Emulator and I've selected a button (not clicked!) it shows an orange layer over it. When i click it i turns yellow.
On a HTC device the orange/yellow overlay is green. On a Samsung Galaxy S it's blue.
I want my app to have the same selection color's throughout the whole app (Blue to be precise).
Is this possible? If so, how?
I think link provided below could be helpful for you
link is: http://groups.google.com/group/android-developers/browse_thread/thread/a7ff938ce09e7c37
Yes it is possible. Use Themes to apply style to the whole app.
You r right
But u also set background color at runtime
& Another
possibility that may be HTC /Samsung has different Android Version ?
so this Happen
Create a selector in your drawable folder
for example drawable/item_selctor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/item_button_selected"
android:state_pressed="true" />
<item android:drawable="#drawable/item_button_selected"
android:state_focused="true" />
<item android:drawable="#drawable/item_button_selected"
android:state_selected="true" />
<item android:drawable="#drawable/item_button" />
</selector>
In your code or xml file use
item.setBackgroundResource(R.drawable.item_selector);
in code
or
android:background="#drawable/item_selector"
in xml layout file