ToggleButton per Lollipop - android

I want my ToggleButton to like like this .
But with this code , it always shows me the older toggle button.
Am running the code in Emulator with API 21 only, Am I missing something here. My code snippet is
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

Found a solution.
Using Android support library. Code snippet is..
<android.support.v7.widget.SwitchCompat
android:id="#+id/id_useridview_switch"
android:layout_marginTop="24dp"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:theme="#style/colortoggle"
/>
Thanks Selvin, got a clue from ur and on what to search

In this code you just set the width and height of your toggle button!
for Android L toggle button you should use support libraries to achieve that!
google something like these:
android L Toggle button support libraries
Also search in Github.com

Use Switch instead of toggle button you will get what u need. No need for external libraries

Related

Correct way of applying material design to checkbox on old devices

I have a checkbox that on Lollipop devices looks like material design guildelines suggest. However, when I open this check box on old android devices, it looks like a default checkbox there.
What is the right way of making sure ALL standard components look on old (14+) android versions same as in Lollipop?
Use support libraries and android.support.v7.widget.AppCompatCheckBox
<android.support.v7.widget.AppCompatCheckBox
android:id="#+id/checkbox_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
/>

Extended Android Floating Button

I developed Android Application and I want to use extended floating button like floating button on Path Application in my layout. I hope someone can give me example about the code how to make this things. Thank You.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hellooooo"
app:icon = "#drawable/pass_resource_here"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
</com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton>
Here's a detailed tutorial on how to create a good extended floating button with animations https://www.learn2crack.com/2015/10/android-floating-action-button-animations.html
Try using this library and modify it to your liking by using the sam ple project in the library
https://github.com/oguzbilgener/CircularFloatingActionMenu

How to add image buttons with ripple effect in cardview?

I'm looking at implementing a cardview which has a button with the ripple effect.
I'm talking about something like this :
https://lh5.ggpht.com/uTRdkJMNyy3KasauJsyGTTRHn5EZBtmA3-BVHCaHWiqBIF_XQmJg_MuE8OdisvefdEk=h900-rw)
I'm trying to implement the download/share button as present on those cards.
Should I be using an ImageButton or something else?
Also, how can I extend the same support for pre-lollipop devices?
UPDATE:
This is the code I'm using right now. It gives me an image button but I'n not able to get touch/ripple effects. The android:foreground property works for cardView and gives the ripple effect, but not for ImageButton.
<ImageButton
android:id="#+id/ib_open_map"
android:background="#drawable/ic_directions_grey600_36dp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
I think this can be interesting for you.
You will have to import or link the library to be able to use it.
Here is the link to the library :
Link to the library
It is easy to use and it is based on imageView.
Hope it helps you :) Let me know
EDIT
Editing my link for your update :)
Take a look at this : MaterialRipple

make Android Textview or EditText selectable

I want to make EditText or Textview selectable in my android project .
project is for android 4.0+ . I add this : txtView.setTextIsSelectable(true) and also : txtView.setCustomSelectionActionModeCallback(new myCallback());
to make my custom selection menu .
but this error happend when i want to select the text .
W/TextView﹕ TextView does not support text selection. Action mode cancelled.
i searched about the error but didn't find the solution .what should i do ?
<TextView
android:id="#+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text="" />
*API Level 11 and up only
setTextIsSelectable does fix the problem on Android 7.1.1 for sure. The setEnabled(false) and then true didn't work.
editText.setTextIsSelectable(true);
My exact situation was having setFocusable(false) and adding an onClickListener, then setting setFocusable(true) and onClickListener(null) gave me the error in the OP.
(not correct syntax but you get the idea)

How to make android:background="?android:attr/selectableItemBackground work in API level 8

I have a button code, where in i dont want border for this button, so for that i set propertie "android:background="?android:attr/selectableItemBackground", but it will not work in API version 8 i.e in Froyo emulator. Please provide me the alternatives.
<Button
android:id="#+id/serviceContactNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/icon"
android:layout_alignLeft="#+id/serviceName"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:freezesText="true"
android:textSize="30dip"
android:background="?android:attr/selectableItemBackground"/>
Thanks in advance.
Borderless buttons are part of the Holo theme which is not available to earlier API versions by default. You can however use HoloEverywhere to make the theme available. At this time it does not actually support borderless buttons either but you can get the same effect by setting the buttons background to android:background="#drawable/list_selector_holo_light"
if thats too heavyweight a solution either extract the appropriate assets from holoeverywhere or from \android-sdk\platforms\android-16\data\res\drawable and put them into your own project
Check if the answer I found in this question works with you: My app force closes on setcontentview when using the holoeverywhere library
style="?borderlessButtonStyle"

Categories

Resources