i want to remove default right shadow in a Button but i don't know how to do it, i tried also to set his background transparent, but it didn't work.
I'll post here my code and what i'm getting now.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/rel1"
android:background="#drawable/search_rounded" <!-- drawable background with blue gradient-->
android:padding="3dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textView"
android:text="Latest Chapters"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#0361c9"
android:padding="5dp"
android:gravity="center"
android:layout_toLeftOf="#+id/backToTopBtn"
android:layout_toStartOf="#+id/backToTopBtn"
android:background="#drawable/edittext_rounded" <!--white background with rounded corners-->
android:layout_marginRight="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Back to top"
android:id="#+id/backToTopBtn"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:background="#android:color/transparent"/> <!--setting right button's background transparent-->
</RelativeLayout>
I want to remove that shadow line between textview and button
put
android:background="#null"
Related
I have this problem while using https://labs.udacity.com/android-visualizer/, I can't move the bottom buttons (from the left, bottom side, that it wouldnt be stuck to the sides of the screen but had a bit of a gap.I added the picture, those are the buttons with white background, foto ->Sides
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2b580c">
<TextView
android:textStyle="bold"
android:text="VTMC - Mūsų nuotraukos"
android:layout_width="match_parent"
android:layout_height="70dp"
android:textColor="#android:color/white"
android:textSize="22sp"
android:background="#2b580c"
android:gravity="center"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:scaleType="centerCrop"
android:src="#drawable/grass"/>
<Button
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Atgal"
android:background="#FFFFFF"
android:textSize="20sp"
android:padding="4dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/>
<Button
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Kitas"
android:background="#FFFFFF"
android:textSize="20sp"
android:padding="4dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</LinearLayout>
From what I understand you want the buttons to be in the bottom corners yet have some space between the buttons and the corner of the screen.
Add a margin to the buttons
android:layout_margin="(size)"
If you want to customize if further you can add a margin to the right,left,bottom, or top.
Delete
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
from first button and
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
from second one.
So I have a custom Header view that contains several widgets. My idea is to have a frame layout with ImageView (icon) aligned parent start and ImageButton (menu) aligned parent end. Also, TextView (title) to right of ImageView.. Those should always be visible.
To right of ImageView(icon) there should be a TextView (title) whose text should expand based on visibility of other widgets on the right side of it..
So the order from left to right goes like this: ImageView(icon) - TextView (title) - ImageView (unread messages) - ImageView (battery) - ImageButton (menu)
The problem is, the text from TextView goes behind the widgets on the right side of it, like it's visible on this image:
Here is my xml preview :
And this is the actual xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="58dp"
android:background="#color/view_controller_header">
<FrameLayout
android:id="#+id/frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_margin="10dp">
<ImageView
android:id="#+id/imageViewIC"
android:layout_width="#dimen/view_controller_header_icon_width"
android:layout_height="#dimen/view_controller_header_icon_height"
android:layout_gravity="center" />
<TextView
android:id="#+id/textViewKK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:gravity="center"
android:padding="10dp"
android:shadowColor="#color/text_shadow"
android:shadowDx="-1"
android:shadowDy="-1"
android:shadowRadius="1"
android:textColor="#color/main_text_color"
android:textSize="#dimen/view_controller_header_kk_texSize"
android:visibility="gone" />
<ProgressBar
android:id="#+id/progressBarVC"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</FrameLayout>
<TextView
android:id="#+id/textViewDName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginRight="#dimen/view_controller_header_margin2"
android:layout_toRightOf="#id/frame"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:gravity="center|left"
android:maxLines="2"
android:textColor="#color/main_text_color"
android:textSize="17sp"
tools:text="This is the text that is too long .........." />
<ImageButton
android:id="#+id/imgSubMenu"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_gravity="center"
android:background="?android:selectableItemBackground"
android:scaleType="center"
android:src="#drawable/ic_more_vert_white_24dp" />
<LinearLayout
android:id="#+id/bat"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toStartOf="#id/imgSubMenu"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageViewBattery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:visibility="visible"
app:srcCompat="#drawable/ic_battery_full" />
<TextView
android:id="#+id/textViewBattery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible"
tools:text="100%" />
</LinearLayout>
<TextView
android:id="#+id/unreadMessages"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_centerInParent="true"
android:layout_toStartOf="#id/bat"
android:background="#color/color_widget_security_back_red"
android:gravity="center"
android:textStyle="bold"
android:visibility="visible"
tools:text="2" />
Any ideas, why does this text goes behind those widgets? I want it to resize if batery and unread messages are visible, like it goes into two lines instead of one, or to show ... if it's too long..
Probably you forgot add one more properties text as below :
android:layout_toLeftOf
android:layout_toLeftOf="#+id/imgSubMenu"
As per you requirement you want show text right to left icon and left to right menu icon but you add one relative reference toRight not toLeft so it's overlap on right side menu icon
I would like to position the text in my button like this:
At the moment the text is positioned in the bottom left corner of the button:
I have four rows of this type of buttons and in every row there is two buttons. Here is my code for one row of buttons:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/main_fashion_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/thumbnail_channel_fashion"
android:text="Fashion"
android:textColor="#FFFFFF"
android:gravity="bottom"
android:layout_weight="1"/>
<Button
android:id="#+id/main_science_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/thumbnail_channel_science"
android:text="Science"
android:textColor="#FFFFFF"
android:gravity="bottom"
android:layout_weight="1"/>
</LinearLayout>
how can I add some padding to the left and below of the text without moving the background image? Margin seems to add white space around button and padding creates space between background image and button's edges.
Thanks for help!
You can use this
<TextView
android:id="#+id/main_fashion_button"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#mipmap/ic_launcher"
android:text="Fashion"
android:textColor="#FFFFFF"
android:gravity="bottom"
android:padding="10dp">
Check this out
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/image" />
<TextView
android:id="#+id/imageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:layout_alignBottom="#+id/imageButton"
android:text="FASHION"
android:padding="16dp"
android:textColor="#fff" />
</RelativeLayout>
I would like to achieve the following result where there is a transparent background over the name.:
So far this is what i have done (ignore the black border surrounding the image):
i would like to have a transparent background (actually a colored background with its opacity adjusted).
Here is the XML code i have been using:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="#+id/iconItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:src="#drawable/shout_ic"/>
<TextView
android:id="#+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_alignBottom="#+id/iconItem"
android:paddingBottom="5dip"
android:textSize="10sp"
android:textColor="#FFF"/>
</RelativeLayout>
Can anyone points me to the right direction on how to achieve such things? Thx
In your TextView definition, add:
android:background="#8888"
888 being a mid grey (888888), with 8 being a mid alpha (88)
OR
android:background="#8000"
000 being a black (000000), with 8 being a mid alpha (88)
You can set background color through xml as shown in other answers.
Also dynamically you can getBackgtound and set alpha.
textItem.getBackground().setAlpha(100); // int value between 0 and 255
Add the background property to your text view like this:
<TextView
android:id="#+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_alignBottom="#+id/iconItem"
android:paddingBottom="5dip"
android:textSize="10sp"
android:textColor="#FFF"
android:background="#70000000"/>
Try adding
android:alpha="0.5"
to the TextView, it should make it semi transparent
Add android:background to the textView
<TextView
android:id="#+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_alignBottom="#+id/iconItem"
android:background="#80000000"
android:paddingBottom="5dip"
android:textSize="10sp"
android:textColor="#FFF"/>
And you can change the Transparency according to the percentage
Check this understanding the Color codes in android
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="#+id/iconItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/shout_ic"/>
<TextView
android:id="#+id/textItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignBottom="#+id/iconItem"
android:paddingBottom="5dip"
android:textSize="10sp"
android:textColor="#FFF"/>
</FrameLayout>
I have an ImageButton and I want to show a text and an image on it. But when I try on emulator:
<ImageButton
android:text="OK"
android:id="#+id/buttonok"
android:src="#drawable/buttonok"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I get the image but without the text. How can I show the text? Please help me!
As you can't use android:text I recommend you to use a normal button and use one of the compound drawables. For instance:
<Button
android:id="#+id/buttonok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/buttonok"
android:text="OK"/>
You can put the drawable wherever you want by using: drawableTop, drawableBottom, drawableLeft or drawableRight.
UPDATE
For a button this too works pretty fine. Putting android:background is fine!
<Button
android:id="#+id/fragment_left_menu_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_bg"
android:text="#string/login_string" />
I just had this issue and is working perfectly.
It is technically possible to put a caption on an ImageButton if you really want to do it. Just put a TextView over the ImageButton using FrameLayout. Just remember to not make the Textview clickable.
Example:
<FrameLayout>
<ImageButton
android:id="#+id/button_x"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/button_graphic" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:text="TEST TEST" >
</TextView>
</FrameLayout>
Guys I need to develop the setting and logout button, I used the below code.
<Button
android:id="#+id/imageViewLogout"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_30dp"
android:layout_alignParentLeft="true"
android:text="Settings"
android:drawablePadding="10dp"
android:background="#android:color/transparent"
android:layout_alignParentBottom="true"
android:drawableTop="#drawable/logout" />
Actually, android:text is not an argument accepted by ImageButton
but, If you're trying to get a button with a specified background (not android default) use the android:background xml attribute, or declare it from the class with .setBackground();
I solved this by putting the ImageButton and TextView inside a LinearLayout with vertical orientation. Works great!
<LinearLayout
android:id="#+id/linLayout"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="#+id/camera_ibtn"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:background="#drawable/camera" />
<TextView
android:id="#+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/take_pic"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
You can use a LinearLayout instead of using Button it's an arrangement i used in my app
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#color/mainColor"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/ic_cv"
android:textColor="#color/offBack"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/cartyCv"
android:textColor="#color/offBack"
android:textSize="25dp" />
</LinearLayout>
you can use a regular Button and the android:drawableTop attribute (or left, right, bottom) instead.
Best way:
<Button
android:text="OK"
android:id="#+id/buttonok"
android:background="#drawable/buttonok"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Heres a nice circle example:
drawable/circle.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#ff87cefa"/>
<size
android:width="60dp"
android:height="60dp"/>
</shape>
And then the button in your xml file:
<Button
android:id="#+id/btn_send"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#drawable/circle"
android:text="OK"/>
Here is the solution
<LinearLayout
android:id="#+id/buttons_line1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/btn_mute"
android:src="#drawable/btn_mute"
android:background="#drawable/circle_gray"
android:layout_width="60dp"
android:layout_height="60dp"/>
<ImageButton
android:id="#+id/btn_keypad"
android:layout_marginLeft="50dp"
android:src="#drawable/btn_dialpad"
android:background="#drawable/circle_gray"
android:layout_width="60dp"
android:layout_height="60dp"/>
<ImageButton
android:id="#+id/btn_speaker"
android:layout_marginLeft="50dp"
android:src="#drawable/btn_speaker"
android:background="#drawable/circle_gray"
android:layout_width="60dp"
android:layout_height="60dp"/>
</LinearLayout>
<LinearLayout
android:layout_below="#+id/buttons_line1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="mute"
android:clickable="false"
android:textAlignment="center"
android:textColor="#color/Grey"
android:layout_width="60dp"
android:layout_height="wrap_content"/>
<TextView
android:text="keypad"
android:clickable="false"
android:layout_marginLeft="50dp"
android:textAlignment="center"
android:textColor="#color/Grey"
android:layout_width="60dp"
android:layout_height="wrap_content"/>
<TextView
android:text="speaker"
android:clickable="false"
android:layout_marginLeft="50dp"
android:textAlignment="center"
android:textColor="#color/Grey"
android:layout_width="60dp"
android:layout_height="wrap_content"/>
</LinearLayout>
Best way to show Text on button(with image)
Your Question: How to show text on imagebutton?
Answer: You can not display text with imageButton. Method that tell in Accepted answer also not work.
because
If you use android:drawableLeft="#drawable/buttonok" then you can not set drawable in center of button.
If you use android:background="#drawable/button_bg" then color of your drawable will be changed.
In android world there are thousands of option to do this. But here i provide best alternate according to my point of view. (see below)
Solution: Use cardView with LinearLayout
Your drawable/image use in LinearLayout because it shows in center. And with help of textView you can set text on this. We makes cardView background to transparent.
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="99dp"
android:layout_margin="16dp"
app:cardBackgroundColor="#android:color/transparent"
app:cardElevation="0dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/your_selected_image"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Happy Coding"
android:textSize="33sp"
android:gravity="center"
>
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
here i explain some terms:
app:cardBackgroundColor="#android:color/transparent" for make transparent background of cardView
app:cardElevation="0dp" for hide evelation lines around cardView
app:cardUseCompatPadding="true" its provide actual size of cardView. Always use this when you use cardView
set your image/drawable in LinearLayout as a background.
Sorry, for my Bad English.
Happy Coding:)
ImageButton can't have text (or, at least, android:text isn't listed in its attributes).
The Trick is:
It looks like you need to use Button (and look at drawableTop or setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)).