I have a custom spinner dropdown xml file in /res/layout/:
spinner_view_dropdown.xml:
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinner_item_dropdown"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
style="#style/spinner_item_dropdown" />
I'm setting the spinner dropdown via java:
// "Spinner", aka breadcrumbs
Spinner spin = (Spinner) findViewById(R.id.breadcrumb_dropdown);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.breadcrumb, R.layout.spinner_view);
adapter.setDropDownViewResource(R.layout.spinner_view_dropdown);
spin.setAdapter(adapter);
// /"Spinner"
Unfortunately, a white background still exists on the spinner popup regardless if I set the background to transparent.
How do I fix this?
You can override the style for the dropdown, and the dropdown item by using a Theme in your app that inherits from one of the Android themes, then override the
android:dropDownSpinnerStyle, or android:spinnerDropDownItemStyle, and even the android:dropDownListViewStyle attribute of the theme, pointing to your own custom style instead of the Android style that is defined in their theme. I created a fully customized spinner this way, with a transparent button AND dropdown. I even got rid of the dropdown list dividers, and set my own spacing for the dropdown items when I built the tablet app for Fandango (take a look at the sort movies spinner on the main page of the app).
Everything in Android is customizable, you just have to know where to look. ;-)
Try setting on the spinner this:
android:popupBackground="#android:color/transparent"
The layout you're defining is only used for an entry of your drop-down, not the drop-down itself. So setting the background to transparent won't have any effect on its background. But even if it would, setting the background to transparent would still have no effect, because a TextView (actually I believe any view) has a transparent background by default.
That being said, the right question would be: can you provide a custom layout for an entry's parent view (which is probably a List)? As far as I know, the answer is no, unfortunately.
Try
android:cacheColorHint="#00000000"
to get transparency.
I dont know if it works for you but there is a post
http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html
that explains why the moving parts of a list appear in the background color.
Maybe its the same issue with your spinner.
It's a bug in 1.5 I think, see here
http://www.symsource.com/index.php?view=article&id=418&option=com_content&format=pdf
Run it in a 1.6 emulator or device, does it still stay white?
I actually came here looking for an approach to this, I suspect this may involve manually writing to the canvas or something like that.
Any ideas.
P.S. Accidentally posted when I thought I was logged in, anyone know how to get rid of the anonymous comment? Maybe an admin could fix this?
Related
I'm new to app development, so maybe I just made an obvious mistake.
However my problem is, like I mentioned in the title, my preview is not showing the ListView examples (Picture 1 show what I want the preview to show), but when I add an ArrayList and start it on the emulator every thing is displayed correctly.
1 https://i.stack.imgur.com/w4uON.png
2 https://i.stack.imgur.com/6Hneo.png
3 https://imgur.com/sQtBpAo
4 https://imgur.com/a/moT6M4K
In your layout XML (activity_main.xml), you can add the tools:listitem attribute to the ListView to specify a layout to show in the preview. Like this...
<ListView
android:id="#+id/myListView"
android:layout_width="0dp"
android:layout_height="0dp"
tools:listitem="#layout/item_something"
... />
Just replace 'item_something' with the name of the layout you want to use for each item.
PS. When you're in 'Design' mode rather than editing the XML, look for the attributes with a small spanner icon to the left. There are other 'tools' attributes you can use for similar things.
Can Someone please help me out, in android studio there is only one default status indicator(Progress bar) that is vertical. I want to add a horizontal status indicator in my app please help, Thanks in advance.
Try to add this style to your ProgressBar, make sure you don't forget to add wrap_content to your layout-height attribute.
style="?android:attr/progressBarStyleHorizontal"
Also if you would need this, there is a nice option to make your ProgressBar to look like a loading bar, you need just to add this line to your ProgressBar layout:
android:indeterminateOnly="true"
If this has already been asked, forgive me. But I'm wondering if there is a simple way to adjust the transparency for ListView selection. I know how to change the color, but is there any attribute that allows to adjust the transparency? Or would you have to upload some custom background?
If by transparent you mean see-through, and by ListView selection you mean a single item of the ListView, then its called alpha. The link should show you the info for the XML, but you can also set it using setAlpha(), which is accessible to any View.
OK the header says it.
I want to be able to create my own controls such as buttons, textviews, edittext boxes, spinners, and so on. I can create the images in CS5 but how do I turn those images into functional GUI components? Thanks
You mean you want to create a custom looking version of those controls right?
You could make an ImageButton component for any custom button you made, and use the attribute android:src, like
android:src="#drawable/your_image"
Similarly for EditText you can use the attribute android:background.
Edit:
The android controls are not stored as standard image files anywhere accessible. The standard designs that you mentioned are the default look of the elements.
To change it, you would have to create the background yourself and store it as a .png file in the drawable folder of your project. Make sure you name this file only in lower case and with no special characters like spaces etc.. Copy this file into all the drawable folders(drawable-hdpi,ldpi etc).
Then you have to refer to this file within your box as
<EditText
android:background="#drawable/your_edit_text_graphic_file_name"
android:text="#string/sample_text"
android:layout_width="match_parent"
-- all other attribute declarations --
</EditText>
Similarly, for other elements you would have to use android:src like is mentioned earlier to refer to your own graphic!
Hope this helps!
You just create your CustomView extend View or TextView.... and implement event handle. Android Developer had a training about this Custom Components . When you finish you can find your custom view in GraphicLayout => CustomView in Eclipse and add like normal components.
Images just provide nice appearance not event handle so you can not just make image to component
You don't have to use CSS in case of android you have to use XML file for UI designing.You can create UI in XML statically or dynamically(i.e. Programmatically). You can create button in android in the following manner.
<Button
android:id="#+id/buttonStart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your btn Name"/>
You can access this button in your java file by getting id of button and use it.
Hope this helps.
For more info read this post http://developer.android.com/reference/android/widget/Button.html
My app tracks how players at a pokertable play. I give my users the option to save up to 50 players stats in the form of a 'Player' object stored inside a JSON array within sharedPreferences. Allowing the user a way of selecting and loading one of these players has proven difficult.
An alertDialog seems to small, a new activity seems a bit overboard for what is essentially just a large menu and I fear passing my objects to it will prove difficult. A viewFlipper sounds interesting but I've no idea whether it's suitable.
How should I go about doing this? Filling the screen with dozens of buttons is really all I wish to do.
I agree that creating a new activity for this would be an overkill. One way to address this would be to have a GridView populated with your "buttons" - and the user would select one from the grid by clicking it. The question is where/how to display this grid.
ViewFlipper is a nice option in my opinion. The way you would go about it is place your existing layout inside the view flipper, then put the GridView into the ViewFlipper after your existing layout:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/flipper">
<LinearLayout ...>
<!-- this is where your main layout goes -->
</LinearLayout>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/player_select"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewFlipper>
Then in your activity set up the Adapter for your grid view and the OnItemClickListener - to do something when one item is clicked. Finally somewhere (either in the main layout or in the options menu or elsewhere) provide something to display this grid view. In the handler code for that action you'd have something like
ViewFlipper flip = (ViewFlipper)flip.findViewById(R.id.flipper);
flip.showNext();
This would effectively hide your main layout and show the grid instead. And at the end of your OnItemClickListener you'll have
ViewFlipper flip = (ViewFlipper)flip.findViewById(R.id.flipper);
flip.showPrevious();
This would hide the grid view and navigate back to your main layout. Feel free to add any animation you like for the transition (e.g. 3G flip animation looks particularly nice).
Try an AutoCompleteTextView. Start typing one of the names, and a list of all possible matches pops up.
Screenshot from Google's tutorial:
I went with a ListView. It combines the filtering and tidyness of the autocomplete yet displays the names so users don't have to remember them like the ViewFlipper solution.
Thanks for both answers, they are both good solutions that helped me come to the solution I needed which combines the two.
The autocomplete had the advantage of searching so I could extend the number of players a user can save to my hearts content, it also looked neat but could not easily see the whole list which for poker players was necessary as the names you give when titling your notes are rarely your fellow players name but rather off the cuff nicknames based on their appearance/playing style. Hence using autocomplete the user will have to remember the nicknames they gave which over 50 players and potentially months apart would prove tricky.
Alek Gs solution would avoid that problem but would not be suited large numbers of names or long names for that matter as the buttons would be off fixed sizes.