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.
Related
I am creating a form in which i have to put five different smiley icon in rating bar to get feedback from user.
I tried but at a time only one type of icon is being displaying.
I am trying by changing style in style.xml
<style name="customRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingstars</item>
<item name="android:minHeight">32dip</item>
<item name="android:maxHeight">32dip</item>
</style>
Please suggest me how could we achieve this in android?
Thanks in advance.
Here is a ratingbar which uses face morphing animation to animate different smiley reactions.
SmileyRating github
You can clearly see that the smiley is changing its reaction slowly.
From my experience with RatingBar I would say ditch it completely and implement your own mechanism for getting the feedback. Maybe a horizontal linear layout with 5 circular buttons?
I had the same problem and the only way I found is to make a LinearLayout with the 5 different faces as elements, and manually control touch position to change faces from selected to unselected, emulating how an old plain android RatingBar works.
I recently made a library out if this implementation, maybe it can help you.
An example of the library working with faces:
Checkout this EmojiRatingBar library.
In my app the user views a document they have made. It includes various elements including Buttons and ToggleButtons.
The user can set a custom theme that changes the Typeface and Text color used in the TextViews/EditTexts as well as the background color of the layouts.
All these elements are generated at runtime.
What I would like is to make the Buttons/ToggleButtons respect the style the user chooses. I can determine the basic background color I want for the buttons at runtime, but if I use View.setBackGroundColor() it becomes a flat colored rectangle whereas I would like to retain the border/shadow effect, plus the color change when pressed. i.e. i would like it to look and behave like a Button, just shaded a different color.
Is it possible to get what I want, given that until the app is running the actual colors required remain unknown?
Rounded corners, shadow effects, etc are often accomplished in Android by using images. See this developer documentation for an explanation of how that works.
A widget can have either an image background, or a solid color background. So, by setting the background color you are override the background image. If you want to change the color without losing everything else, you need to edit the image files.
Generally you can't change styles programmatically; you can set the look of a screen, or part of a layout, or individual button in your XML layout using themes or styles. Themes can, however, be applied programmatically.
There is also such a thing as a StateListDrawable which lets you define different drawables for each state the your Button can be in, whether focused, selected, pressed, disabled and so on.
For example, to get your button to change colour when it's pressed, you could define an XML file called res/drawable/my_button.xml directory like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/btn_pressed" />
<item
android:state_pressed="false"
android:drawable="#drawable/btn_normal" />
You can then apply this selector to a Button by setting the property
btn.setBackground(drawable);
Hi I am a beginner in android and I want to know how to customize buttons,check box etc., I searched in web but found many ways and got confused...
Can you please tell me what are the ways to customize android widgets, can we do that using css, like we do for the HTML?
Thanks in advance...
There are a few ways. You can use 9patch to edit the files inside the SDK(which will typically be C:\Android\SDK\platforms\android-19\data\res\drawable-hdpi) - Android-19 is the api level, and then set them in your xml layout under the widget you want with
android:background="#drawable/your file"
Another way is to create a selector(Recommended because it can handle stuff like when clicked and more), shape(Simple creation with corners and stuff), layer list(Advanced selector) or solid(just a color) in /drawable and then set them in your xml under the widget you want with
android:background="#drawable/your file"
An example of the second solution can be found here android button selector
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
I'm looking to add new states to a TextView. I chose TextViews because they're a relatively simple controls and I want use this in a widget so I really want to cut down on nested controls as much as possible. I need to define custom states for my TextViews. States like, not_started, in_progress, completed, missed, did_not_do, etc...
I want the background and font color to change with the states. How can I do this?
I can use a Level-List selector to handle my "custom states" and define my states as integers.
http://developer.android.com/reference/android/graphics/drawable/LevelListDrawable.html