Android - How to give your layout a 3D style? - android

I was surfing the web to find a new style for the android layout and I find a pretty interesting one. Here is the Image.
I know more than basics about layout, but what I wanna is how can I give a 3d style look like in the above image? Especially that #7881 Code Box.
Here is Something that I have tried.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="-25dp"
android:top="-25dp"
android:left="25dp"
android:right="25dp">
<rotate android:fromDegrees="20">
<shape android:shape="rectangle">
<size
android:width="50dp"
android:height="100dp"/>
<solid android:color="#E30B3E"/>
</shape>
</rotate>
</item>
</layer-list>
The output is this
Overall it gives the textview a 3d look but I want something like that in the image.
Any Suggestions?

Its pretty much simple just use android:rotationX property on the CardView
like this
<com.google.android.material.card.MaterialCardView
...
android:rotationX="20"
...

That's easy as long as the box should not be animated in its shape.
Go to https://www.figma.com/ and start a new project (it's free)
Export any shape you create there as svg
Import this svg into Android Studio using the Resource Manager
add your new drawable as background of the box.
Additional input, so your 50 points aren't wasted ;) :
You find several Android Presets for figma. Like UI Elements or buttons. For example here. For more just google for "Figma Android UI kit"
You can edit the generated SVG to your likes. Since it is only a text file, you can customize its colors (also using backgroundTint in xml), etc.

Related

How to make a button with rounded edges?

what is the essence of the question:
Why is the color that I write in solid in the shape not taken into account
Why do I have a white background on the back of the button now (attached a photo)? I don't understand where I can fix it
I found a video on YouTube and there was the following solution: Create an xml file in drawable and there I specified the following:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#color/teal_700"></solid>
</shape>
</item>
</selector>
The problem is that when the videos came out, there were no themes and everything worked out perfectly right away, and I tried to figure out why I didn't apply color to the button if I set it in the shape, but I never figured it out and it doesn't take into account my color that I set in solid :) I decided to change the primaryColor in the theme to the color I needed and then it applied.
And can you also throw, please, useful modern resources to the latest versions of android studio? I'm just learning, so I haven't found much yet and it would be interesting to see some examples for new updates, because all the videos are from earlier versions and some of them don't converge, as, for example, now in the question
If there are not enough details to solve the problem, then write to me
To make A Button Round Use MaterialButton
<com.google.android.material.button.MaterialButton
android:layout_width="100dp"
android:layout_height="50dp"
android:text="1"
app:cornerRadius="18dp" />

Android add border to button without losing material theme (using drawable)

I have a simple button
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/add"
android:backgroundTint="#color/add_bg"
android:textColor="#color/add_fg"
<!--android:borderColor?="#color/button_border"-->
android:text="#string/add"/>
I would like to have white background, blue text and blue border around. I am aware that I can achieve that through a drawable as shown here and in numerous other places. However I have observed that if you add a drawable to the button then it will lose all of its material properties (such as shadow and also upon clicking having the fancy ripple animation). So how would I add a border around the button without losing the material theme animations (shadow and tipple animation on click)?
Most of the items that android comes with are simply a pre-packaged set of attributes.
It would be almost impossible to expect the Android API developers to include a pre-packaged set of attributes for every possible color/border combination, but there is always a solution!
Unfortunately,as you mentioned, the solution does reside in creating your own custom XML file which can often be intimidating until you get the hang of it. Once you do, you too will marvel at the flexibility it allows.
Specifically for your situation, there are two options...
1) Create a custom XML border drawable.
2)under your buttons background property set your new custom border drawable
3)then also set the ripple effect under your buttons xml properties by adding:
android:foreground="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
----OR----
A more complex way is to make a drawable like the one below. This will add the "ripple" button effect as well as a custom shadow, button color, and border color!
"For anybody reading this later that may be less experienced)
1)In your project view go to res/drawable
2)right click the folder itself and select new/drawable resource file
3)Enter a file name my_ripple_button.xml(the root doesn't really matter because you wil replace it with the below code)
4)Click on the text tab if you aren't already there
5)select all text and basically replace with the following: (creating a custom color border is basically the same steps)
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/colorPrimaryDark">
<item android:id="#android:id/ripple">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimaryDark" />
<corners android:radius="#dimen/button_radius_large" />
</shape>
</item>
<item android:id="#android:id/background">
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#color/colorPrimaryLight"
android:startColor="#color/colorPrimary"
android:type="linear" />
<corners android:radius="#dimen/button_radius_large" />
</shape>
</item>
</ripple>

How to draw a semi-oval shape using shape drawable in xml (Android)

I am struck at this problem of creating the UI in android. I need a xml-based solution to this problem. I don't want to use any SVG or PNG image to achieve the solution. Is there any way to achieve this of view in android.
You should be using a <layer-list> element of xml to draw such a UI.
Following code will be used to create oval shape:
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#AAAAAA"></solid>
<size android:height="100dp"
android:width="60dp">
</size>
This leads to the following shape:
Once you know how to draw an oval shape using xml. Now next step for you is to learn how to use <layer-list> to achieve desired output. To learn using <layer-list> you can follow this tutorial.
By creating a new drawable file which will describe the look of the widget you want to draw,more or less.You can then set it as background for which widget you want to change the original look of. I would recommend starting with rectangle if you want to achieve the shape shown in your question. the drawable file will look something like this:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#000"/>
<corners android:radius="150dp"/> <!-- The value here should specify How much ovally you want shape be -->
</shape>
and then assigning the background of the widget to this drawable should do the trick, something like this:
<LinearLayout
android:background="#drawable/oval">
Hope this was helpful :D

How to preview xml drawable?

I'm working on pretty complex xml drawable and i was wondering if there is any tool/plugins which allow me to preview my drawable ?
I'm looking for something similar to the "Graphical layout" tab available for layout.
For example if i have something like this :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="0dp" android:right="0dp">
<shape android:shape="rectangle">
<gradient android:angle="-90" android:startColor="#2B2B2B"
android:endColor="#000000" />
</shape>
</item>
<item android:top="1sp" android:bottom="26sp" >
<shape android:shape="rectangle">
<solid android:color="#10ffffff"/>
</shape>
</item>
</layer-list>
How can i preview the shape and gradient ?
And i'm probably dreaming , but is there any graphical tools to build a drawable ?
In Android Studio do this: View -> Tool Windows -> Preview
Android Studio has support for this starting with version 0.3.2: http://tools.android.com/recent/androidstudio032released
Click on PREVIEW on the right side of the window.
In Eclipse
Create new layout with root LinearLayout.
Open Outline view.
In properties table find View.Background.
Press button ...
Now you can chose Color and Drawable resources and there is small preview.
Android Studio offers a nice plugin named
"Vector Drawable Thumbnails"
This adds a nice overview over all vector drawables in your project.
Just have a look at the side bar and open the view. You will get a thumbnail table of them.
Another possibility:
Just create a new layout "test", goto graphical layout, create a button inside (or any view), and assign the drawable to the button's background. The drawable is rendered (its normal state).
Android Studio 2X
View -> Tool Windows -> Preview
Or click on Preview on the right side
One way to preview the resources is by using the Resource Manager in Android Studio. It's visible as a separate tab:
If you would like to preview selector you can find tabs with states on Preview Panel
The Preview options mentioned in previous answers aren't there in Android Studio 4.0. Look for this segmented control in the top-right of the editor tab instead.

Android: Standard 'Next' Button and Background

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>

Categories

Resources