Hi all I am trying to show an Android spinner, but not show it as grayed out. I tried using setFocusable(false), which works fine on edit boxes, but not on spinners. I don't want the spinner to changeable unless I tell it to be. Basically I have a screen displaying data that I want to put in "update mode". Until the user has chosen to update the data, it should be view only. Any ideas?
maybe you can create a custom selector and set it to the spinner background,
check out this link for the selectors
I ended up cheating a little. I got the background image before disabling the field, then set the background to that image after disabling the field.
// Deal with spinners. I don't want to gray out the background
// because it looks bad against our dark theme.
Drawable d = type.getBackground().getCurrent(); // the enabled background
type.setEnabled(enabled);
// set all of the spinners back to the enabled background
if(!enabled){
type.setBackgroundDrawable(d);
}
Related
I am trying to make an app using App Inventor.
The app has more functions, but I am stuck at the I would say "basic" one.
What I want to do is basically change the background color (or color of any element) by calling the color from list stored in TinyDB.
I have two screens Screen1 and a Menu screen.
I am tring to call TinyDB while Screen1 initializes and set background color of app on the first in the list.
Further I want to let user to choose a color from list on the other screen "Menu". After picking a color change the color on both screens.
I tried to make it following the instruction https://sites.google.com/site/blocks123/playing-with-colors , but it is little bit confusing for me.
On the printscreen i have the TinyDB blocks on the Screen1.
Is it possible on Screen1 just call/initialize TinyDB but has the TinyDB blocks on other screen "Menu"?
And when I have TinyDB and lists of color how to change the color on the chosen one?
Thank you Taifun. Your tutorial was helpful for me, evethought it is bit confusing with variables which aren´t described there. Anyway I tried to do it a bit on my way and I think I am going the right direction.
As it shown on second image I made it on the "Menu" screen and trying to save my choice to [TinyDB].
It works almost fine but except the error when "Menu" screen inicialize. I don´t understand why I am getting this message while to value is in the list? And the other way how to pass the BCurrentColor variable to "Screen1"? If I use set.Screen1.BackgroundColor it doesntWork
Well now I know I am close, I can almost fell it in the air. It is properly change background color on "Menu" screen but some how it doesn´t saves the choice to [TinyDB] as I describes at comments. Where I went wrong?
I hope when I save the color "code" to database I can call it on the other screen.
As Taifun mentioned the problem was with the variables BCurrentColor and BCurrentColorName. After I changed them to values and the trigger after selecting color from list sets it to required color.
Then I can call it from TinyDB. It works fine.
I want to dim the background around a spinner dropdown, but I cannot find any way to accomplish this.
Research has uncovered the possibility of placing a fullsize framelayout between the activity and the spinner dropdown, and setting a background colour and alpha value on this.
However, I cannot find anyway to determine when the actual dropdown is getting displayed so that I can insert this frame.
Am I looking at this problem the wrong way? Surely there must be a way to dim the background behind a spinner dropdown.
I think you should be able to use the Spinner.OnClickListener. When this is called, you can dim the screen with your framelayout
I ended up using something very similar to this answer in a related question. https://stackoverflow.com/a/18636385
Along with a RelativeLayout in the activity to act as a dimming mask.
I am working on a game project.
I have 4 buttons on my screen. User has to select one of the 4. If user selects the correct one, it works fine. but if user selects incorrect one, I want to highlight the correct answer even though user didnt clicked it.
I have presentation due tomorrow. Can anybody point me to some example source or explain it here, as to how can I accomplish it.
You can set the correct buttons background color or image while clicking other buttons
Whenever user clicks on the incorrect button simply call :
correctButton.setPressed(true)
This will highlight the correct button as per your requirement.
you can do one thing..
Call Button.requestFocus() method to get the focus.
Create a custom selector for you Button's background. there
< item android:state_focused="true" android:drawable="#color/your_color" />
I have a group of buttons which enable user to select certain views on the touch screen.
I want to have the user know which view is active by showing a halo (or any other style) around the button. I mean when the button is clicked it's normal state is changed to different style but it is still normal.
I googled and checked in stackoverflow, that it is not possible to change the style at runtime.
How can I achieve the desired effect?
I have some silly ideas which I won't implement unless as last resort, like making two buttons at same positions and changing their visibility.
Or I can put each button in it's own linear layout and then set the background color of each of them, if it is possible.
Or some ImageButton manipulation maybe.
I have already overridden the default style for button for normal pressed states.
And setting focus(when in focusInTouchMode) causes problem, so that's a NO (already tried that).
Even if style can't be changed, please advise some tip to achieve the effect, it's not necessary to do it the style way. I just want o let the user know which view is selected through buttons.
use state list and set its focussed state drawable as the button with a ring around it and then at runtime say button.requestFocus(). see here for more on state list...
Go for selector xml background for each button. Best Resort
Check this link
How to set image button backgroundimage for different state?
Hpoe this helps
or you can use like ::
Button button;
public void onClick(View v)
{
button.button.setBackgroundColor(**color**);
button.setBackgroundResource(**res**)
}
In the following picture you can see an android.widget.EditText (left half) where some text is selected:
Strange thing is: You can see the start and end marker of the selection but the actual selection is not highlighted.
I wonder what I forgot or what I did wrong here. How can I ensure that the selected area is highlighted using an appropriate background colour?
for more on StateList, refer this http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
After a little more experimenting I found the following:
the colour of the selection background is indeed set by android:textColorHighlight.
The selection is not highlighted when the entry field is in read only mode.
So for me there is nothing to be done about it and i just have to live without a highlighted selection.