I'm developing an android app and want to add a button (widget?) with icon.
As i understand, it's appearance should be described in xml resources.
I can do it in java code, but it seems incorrect.
public class VideoButton extends android.support.v7.widget.AppCompatButton {
private void onCreate(){
setBackground(ResourceManager.getDrawable(R.mipmap.roundbackgroundnormal));
Drawable icon = ResourceManager.getDrawable(R.mipmap.video);
icon.setBounds(6,0,50,44);
setCompoundDrawables(icon,null,null,null);
setPadding(12,8,8,8);
...
So, i wrote an xml replacement code that doesn't fit my expectations
<blah.blah.blah.ui.widgets.VideoButton
android:id="#+id/record"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#mipmap/roundbackgroundnormal"
android:drawableStart="#drawable/video"
android:visibility="visible" />
I expect this (ty java),
but get this
How to fix my xml code to get a proper result?
TY, if possible fix terminology.
Better to use FloatingActionButton
Floating action buttons are used for a special type of promoted action. They are distinguished by a circled icon floating above the UI and have special motion behaviors related to morphing, launching, and the transferring anchor point.
Compile this dependencies
compile 'com.android.support:design:27.0.2'
SAMPLE CODE
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_check_box_black_24dp" />
RESULT
OR
You can use ImageButton
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 setImageResource(int) method.
SAMPLE CODE
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_check_box_black_24dp" />
OUTPUT
<blah.blah.blah.ui.widgets.ViseoButton
android:id="#+id/record"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#mipmap/roundbackgroundnormal"
android:drawableStart="#drawable/video"
android:visibility="visible" />
You can design with your custom icon.png and move it into your project folder
mipmap
android:background="#mipmap/roundbackgroundnormal"
Related
Cuboid circle button is a custom circle button in android (source: Github Cuboid Circle Button).
I'm using that button in my app. It works well, but I cannot find a way to change its color programmatically on runtime.
In the class, before onCreate I have:
com.cuboid.cuboidcirclebutton.CuboidButton btnReplayEnd;
Then in onCreate:
btnReplayEnd = (com.cuboid.cuboidcirclebutton.CuboidButton) findViewById(R.id.btnReplayEnd);
And in the 'setTheme' method (in the same class):
btnReplayEnd.setCircle_color(getResources().getColor(R.color‌.replayNormalDark));
there is no way to change the circler color of com.cuboid.cuboidcirclebutton.CuboidButton programatically you can only change it via xml using app:cub_color="#color/color_03A9F4"
like this
<com.cuboid.cuboidcirclebutton.CuboidButton
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:text="No Border"
android:textColor="#000000"
android:textSize="18sp"
app:cub_border_radius="0dp"
app:cub_color="#color/color_03A9F4"
app:cub_fontstyle="fonts/Bellerose.ttf"
app:cub_hover_color="#00BFFF1"
/>
I have Button in my layout,in that I want to display a down arrow symbol. I defined the Button in a layout file How can I set the down arrow symbol to that button,
can anyone help, thanks in advance......
Taken from the Android API guides on Buttons, you can use an ImageButton.
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/down_arrow_icon"
... />
You can download the down_arrow_icon from a number of resources (like the Google Material icons page) or even create your own image.
Simply use android:drawableRight property. Like:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/your_drawable"/>
I'm drawing an ImageView (a 50% transparent icon) over an ImageButton, but the icon disappears when I click the ImageButton (an Activity transition gets triggered at this moment). That looks pretty awful...
What is the best approach to do this, without actually putting the icon into the src-File of the ImageButton? Is there a way to do it with setting drawables as background or foreground? And what exactly are those two properties for? I can't find any documentation about android:foreground...
BTW: I'm using the new Lollipop shared element transition and testing on a nexus 9.
<Relative Layout...>
<ImageButton
android:id="#+id/imageView1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_width="400dp"
android:layout_height="250dp"
android:src="#drawable/call1"
android:foreground="#drawable/phone" <!-- Does this make any sense?-->
android:transitionName="#string/trans_call_pic"
android:onClick="clickCall"
/>
<ImageView
android:id="#+id/imageButton1"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/phone"
android:layout_alignBottom="#id/imageView1"
android:alpha="0.5"
android:layout_marginLeft="14dp"
/>
</RelativeLayout
The android:foreground attribute is for a foreground selector (added to a FrameLayout). It's not intended to simply draw an image.
One solution would be to wrap the button & the image in a container view and put your transition on the container. This way the two child views would be treated as one.
Try adding a foreground selector to your view. You can extend ImageButton, override onDraw(), and draw the foreground selector after calling super.onDraw(). This will ensure that the foreground selector is drawn on top of the entire ImageButton. More detailed instructions can be found here.
I'm working on an Android widget which essentially places a button on the homescreen. The button uses a selector in order to show a default state and a pressed state. Each state has its own image, as you'll see in the code below.
I already have code to change the hue of an image and return a new StateListDrawable for use in the ImageButton.
My question: How do I actually apply the StateListDrawable to the ImageButton's android:background attribute using the RemoteView?
Here is the XML source for the widget layout:
<LinearLayout
android:id="#+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:background="#drawable/buttonselector" />
</LinearLayout>
Instead of using the hardcoded "#drawable/buttonselector" it needs to be the dynamic selector I'm generating.
I have posted an answer link text which I think is similar to your problem. This, however, involves two layouts that are almost similar. The only difference is the part that should change.
I am looking for a view or some sort of information regarding the bottom bar in default applications of Android such as Email, or Unlock pattern as shown in the picture below. I have not been able find anything about this on Androids site nor from Google searches.
Image: http://img11.imageshack.us/i/viewdn.jpg/
I believe that Christopher is correct; there is no special widget to create the bar in your image. However, if you want to emulate it, you can create a layout and use the style style="#android:style/ButtonBar". That will give you the light gray background and the correct margins.
I don't believe there's any standard view for the button bar used at the bottom of these apps; it's generally just two Button items placed together in a LinearLayout or RelativeLayout.
For example, looking at the Android Open Source Project, you can see the button bar for one of the email app setup screens is defined as two plain old Button objects.
However, it is surprising that Google didn't abstract more of the common stuff into an Android theme or sublayout, rather than having the same views and attributes in each layout XML.
From: http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314
<RelativeLayout
android:layout_marginTop="-45dip"
android:padding="0dip"
android:layout_alignParentBottom="true"
android:gravity="bottom|right"
android:background="#android:drawable/bottom_bar"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Button
android:id="#+id/manual_setup"
android:text="#string/account_setup_basics_manual_setup_action"
android:minWidth="#dimen/button_minWidth"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="-4dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="false"
/>
<Button
android:id="#+id/next"
android:text="#string/next_action"
android:minWidth="#dimen/button_minWidth"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableRight="#drawable/button_indicator_next"
android:layout_marginBottom="-4dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="false"
/>
</RelativeLayout>