How can I add image from src attribute to gradient.xml file in Android?

How can I add image from src attribute to gradient.xml file in Android?



I am new to Android and I want to display image with gradient background. Is it possible to add an image into gradient.xml?



Below is the xml code for this.


<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/bg"/>
<shape>
<gradient
android:startColor="#631f68"
android:endColor="#ff5555"
android:angle="45"/>
</shape>

</item>







As this is on UI, please attach a picture of what you would like to accomplish. Also maybe state your question clearly, because so far I read it as "is it possible to ..." and I would reply "try it out!" :)
– Alessio
Aug 31 at 6:07





you can create here image and than use in this selecter gradiend in layout file
– Ahsan Malik
Aug 31 at 6:09




1 Answer
1



Solution:



In your main_activity.xml,



set the background image for your topmost layout: (Relative or Constraint whatever you are using)



Then take another layout and give height and width to match_parent and apply the below Gradient to the background of it.



Gradient file:


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="@color/colorAccentSecondary"
android:endColor="@color/colorPrimary"
android:startColor="@color/colorAccent"
android:type="linear" />

<corners android:radius="0dp" />
</shape>



Hope it helps.





i tried it but still facing same issue not able to apply gradient to image. please look into my edited screenshot and code
– santosh
Aug 31 at 6:24





@santosh Can you post a screenshot of how you want it to be..?
– Ümañg ßürmån
Aug 31 at 6:30





i have posted once check
– santosh
Aug 31 at 6:31





You mean the second answer? @santosh
– Ümañg ßürmån
Aug 31 at 6:32





yes the second answer
– santosh
Aug 31 at 6:34



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

How do I collapse sections of code in Visual Studio Code for Windows?