One of the application in my mobile has a header like the one shown below in the snapshot. I like the design very much and would like to create one for my application. Clicking the home icon takes the user to landing page(Home page). I have only created buttons of squarish and rounder corners. But not sure, how to create one like the one given below. Any help would be highly appreciated.
Create the image in photoshop or whatever.
Then create an imageview and let it act like a button:
<ImageView
android:id="#+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/button_camera"
android:onClick="onCameraButtonClick" />
onClick is introduced in Android 1.6
or a button and set the background:
<Button
android:id="#+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_camera"
android:onClick="onCameraButtonClick" />
drawable/camera_button should be a state drawable so the user can see when it is being clicked/focused.
in your activity:
public void onCameraButtonClick(View v){
// Do Something
}
It's all here:
http://developer.android.com/reference/android/widget/Button.html
The way that I would do this is just create the buttons in photoshop/GIMP on the same canvas then save each as PNG, you can use the slice tool for this. Then I would just add an attributes to each button. There's attributes that let you set the left margin of say the right button to line up with the right margin of the left button. The backgrounds of the buttons could also be patch9 images, and the icons inside it could be the src attribute of the button view. The button with the camera would have SRC pointing to a PNG that has the camera icon as well as "Camera". And the button itself not having any text.
Related
I have been trying to achieve the Normal android button effects when the button is already set with a background image
But the problem is, once the background is set, the button default nature is gone (shadows, clickable animation etc..)
Can Someone please give me a working solutions for this?
Here's the code to my button
<Button style="#style/Widget.AppCompat.Button.Colored"
android:id="#+id/student"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/student"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintVertical_bias="0.891" />
It looks amazing since I have set a background image but It still looks like you have set an image to a jLabel in Java)
How can I get the default button looks while keeping my background image intact?
Button works by setting the background to a background with the elevation, shadows, ripple, etc. To get the same behavior, you're going to need to set your background to a StateListDrawable that performs the ripple effect and puts the shadows and elevation effects with your image as the background inside of all that. You can't just set the background to be your image, that will lose all of those features. The easiest way to get that right is to look at the AOSP source code and find the drawable it uses, copy it to your project, and edit appropriately.
Basically in Android a Button is just a TextView with a special background preset.
Why don't you use ImageButton widget ? It has the same behaviour as a Button and ImageView combined
Check this tutorial to see how to work with it.
as mentionned in the official documentation
Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by the ImageView.setImageResource(int) method
I am very new to Android Studio and creating apps in general.
I have created an Image Button and uploaded an Image, problem is that I want to make the background of the Button transparent.
This is what I mean:See Example
The background of the left button is black and I want to make it transparent, like the Right Button.
Just put this property inside ImageButton tag:
android:background="#android:color/transparent"
----------OR--------------
You can also user vector image for this:
Click on Vector Asset
Click on small icon image(just below ic_android_black_24dp)
Search any icon and add to your drawable. The icon you are using is appeared in search result. use this list icon.
Try This
<ImageButton
android:layout_width="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/image"
android:layout_height="wrap_content" />
I have an image which I want to use as a button. But I want only the image to be visible as the button, with the shape of the image (I do not want the regular button around the image, nor I want the regular button shape). How can I achieve this? Can I achieve this without designing a custom button?
Check the android developers reference and Tutorial Custom Button. It's exactly what you need!
Set the image with button.setBackgroundDrawable (or Resource, etc.)
Use ImageButton with background property set to some color i.e. #000 and no padding
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:background="#drawable/ic_launcher"/>
Im trying to place an icon thats 16x16 pix within a normal button that I have in a layout. This button also uses another png for its background. The problem I have is not placing it within the button but placing it where I want. When I add it using the following code it places the drawable at the bottom but exactly on the edge of the image which looks terrible.
<Button
android:id="#+id/clearform"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/helpText"
android:layout_alignParentBottom="true"
android:layout_marginBottom="19dp"
android:typeface="monospace"
android:textColor="#FFFF00"
android:drawableBottom="#drawable/cross"
What I would like is to create a button in my layout that possibly has some padding from the bottom but there is no such method or xml attribute that does such a thing the way I would like. Its only left right top or bottom and when I added padding it only placed padding between the bottom of the text in the button and the top of the drawable.
So how can I accurately place an image within the button itself.
I think you can use android:padding for aligning to a greater extent & use android:paddingTop/Right/Left/Bottom to get the exact postion.It would be much easier.
I am displaying a the Terms & Conditions screen of the mobile application as the first screen.
I am using a layout file to display the screen.
Within the layout file , I have two buttons , one for Accept & one for Reject
<Button android:id="#+id/acceptBtn" android:text="#string/accept"
android:background="#drawable/buttons" android:textColor="#color/white"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/rejecttBtn" android:text="#string/reject"
android:background="#drawable/buttons" android:textColor="#color/white"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
The requirement by default is , the Reject button should be in selected condition. Also , currently , because of the android:background="#drawable/buttons" which is an image , the buttons are not getting focussed.
Kindly provide your inputs/sample code/xml to solve the issue.
Thanks in advance.
The problem is that the focus indicator on a button is nothing more than a background image. So when you set your background with a drawable you prohibit the system to use the focused background image when the button changes its state.
A simple solution is to use ImageButtons and to set your drawable as the src attribute. Then you have a button with your image in the center. The underlying background can change to the default focus background image. If you don't want the grey area underneath your image and still want to use buttons you would have to define customs styles depending on the state of the button. Please have a look in this similar post: Remove focus border of EditText
There I already explained this scenario.