I am creating my first Android App that will be making profit, selling it to a company. I am not very advanced yet in Android App Development.
I have two buttons. I have been able to detect when the bottom of a ScrollView has been reached. Once that happens, one of the buttons becomes clickable, Button.setClickable(true);
When the button is not clickable, I would like it dimmed.
Here is an example from another application I wrote of what I mean. It is written in Java, but it is not an Android App.
Many buttons and other components there are disabled until the one with the diamond (turns on scanning) is toggled on. Those disabled components have a dim look to them. I would like to know how to accomplish the same for Android. I have searched Google but not found anything relevant yet.
P.S. If you would like to know more about the software in that picture I created. It is open source and you can check it out here.
https://github.com/BullShark/JSpeak
Similar answer to Anup Cowkur, but I believe it's cleaner and a better practice to define a single drawable with different states.
dimmable_button.xml (put in your res/drawables folder)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item state_enabled="true"
android:drawable="#drawable/clickable_image" />
<item state_enabled="false"
android:drawable="#drawable/dimmed_image" />
</selector>
Then, the layout file where your button is defined:
<button
....
android:background="#drawable/dimmable_button" />
Now, when you do button.setEnabled(bool) the button's background will change automatically to a dimmed one.
Simply make another image with whatever look you want and change the background of the image to it when it is not clickable.
When it is dimmed out:
button.setBackgroundResource(R.drawable.dim_image);
When it becomes clickable again:
button.setBackgroundResource(R.drawable.clickable_image);
Did you tried
myButton.setEnabled(false);?
or
android:clickable can be used via xml
Related
I am working on an already developed application and wish to make it look more responsive
The previous developer used a large number of imageviews instead of buttons with just a src drawable
This means that when the user presses the imageviews they get no feedback that they pressed it
Now what I would normally do is create a selector with the alpha set to 'f' when not pressed and maybe '8' when pressed
Unfortunatelly the number of imageviews and drawables is quite large
Is there a way to set the default behaviour of all ImageViews in my theme so that when they are pressed they change their alpha?
thanks in advance for any help you can provide
I would suggest not fixing one mess with a more complex mess. Imagine maintaining it later. If you are adamant on doing it, I suggest adding the following instead (to add the material design touch ripple reaction)
android:foreground="?attr/selectableItemBackground"
In the theme that will be
<item name="android:foreground">?attr/selectableItemBackground</item>
But if you want to fix it properly for futures sake you could replace ImageViews with ImageButtons that use the current src.
I'm trying to make a widget which is a togglebutton like the ones in the android control widget (the quicksettings for wlan, bluetooth etc.).
Here's how it looks (#Control Widgets)
Does anyone know if this layout is contained in the android sdk or if not how I can make a layout just like that one?
I've already tried some things but I don't know how do to the stroke at the bottom.
Regarding to your issue I searched a little bit deeper.
See: https://developer.android.com/guide/topics/appwidgets/index.html
These are the classes which you can use with an appwidget to implement in your layout there is no such thing like a toggle button, but an imagebutton which I think us exactly what Google is using for the "toggle buttons". Take a closer look on the imagebutton :
https://developer.android.com/reference/android/widget/ImageButton.html
Then you will find out it's exactly what you are looking for.
By default, an ImageButton looks like a regularButton, 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 thesetImageResource(int) method.
I can't imagine that such a complex layout is possible just using clean xml...
Hope it helps now!
I want to know how to get a control that contains list of strings arranged as in an image bellow.
you can see the strings strings added in random way based on its width
I tried to use normal textview with inside a linear or relative layout with but it didnt work.
Can you pleae tell me the best practice to have a control that I pass to it a list of strings and it shows them like the image bellow ?
This can be done using a flow layout and toggle buttons inside it.
A good flow layout is available here.
And the toggle buttons will need a Selector drawable to give it the proper checked/unchecked appearance.
Here is a selector example:
<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="#drawable/rect_tag_checked" android:state_checked="true"></item>
<item android:drawable="#drawable/rect_tag_normal" android:state_checked="false"></item>
<item android:drawable="#drawable/rect_tag_normal"></item>
Google Chips can be used to displays tags. For your use-case Input chips will do the job. Read about it here. The tags/chips are completely customize-able.
The library is available for both Android and iOS so you can provide a consistent user interface for your users on both the platforms.
I have googled this, most of the solutions are using:
1.TabHost with customized style which would cover the separate line between each tab to archive the requirement.
2.On the android developers website, there is a article is using Merge layout to put 2 buttons on top of the background image kind of archive what I want.(http://developer.android.com/resources/articles/layout-tricks-merge.html)
3.What about using button but style the looking like the example below? I don't need the selection, cause each item in the menu will be a button, which takes the user to another page.
I am wondering is there any other solutions apart from these two?
This is something want:
I don't need the menu likes a tab which has selected and unselected, they are better like a button always displaying in certain screen(activity).
Thank you.
You can use simple buttons, and provide any custom background for it. For such simple form as on your screenshot look for this link.
But #Janne write right thing - you should be very careful with transplanting controls from another platforms.
I'm working on a Nexus S and the phone theme uses Black and Orange. I started with a custom button - changing the background from #android:drawable/btn_default to my own 9 Patch image. This is fine and dandy and there are 100's of tutorials and examples of such littering Google.
The problem is I don't want to create a different style of button. I want the UI in my app to as insofar as possible to stay true to the phones own buttons and UI elements. What I want is to create a custom button which looks exactly like android:state_pressed="true" and android:state_focused="true" but instead of orange, blue.
I also want to do this for selected EditText & Spinners and the like.
Am I doomed to backwards engineer each element, guessing each pixel, one for each state and create 9 patch images of them? That's what I've done below for the blue button - as you can see, close but not exact.
Has android given these buttons out somewhere - if that was true it would take an afternoon but it wouldn't be unreasonable to create the same UI set in a different colour.
Or is the a programmatic way of saying "For this app use this theme" that I've just never heard of (Big ask).
If you look in the Android SDK folder under platforms you will see all of the different SDk levels that you have downloaded. Inside each there is a data/res/drawable folder where there are all of the images used in the UI. You can modify those and add them to your own resources. But yes, any change you want to make to the default UI you will need to implement yourself.