Android Spinner Custom? - android

I am trying to create a spinner that looks exactly like the one in this android example, but not sure how or if it has to be custom? I cant imaging it would have to be a custom layout since it is shown this way in their example...
http://developer.android.com/guide/topics/ui/controls/spinner.html#Populate
I am not concerned with how the list looks, but just the way the spinner looks with the lower corner arrow. that is what I want.

This project is an attempt to backport the holo theme by building it into and Android Library project. You can link that library with your project in order to gain access to the holo theme widgets.
I have never used it but I would think that it contains the spinner widget that you are looking for.

Related

Android Exposed Dropdown causes exception

I need to add a drop down to my app, which is running on the AppCompat theme, since we are not using the Material design components, but rather have our own design for buttons, etc.
For a simple feature, I need to use a dropdown and here I think the Exposed drop down from the Material design theme would work nicely.
However, if I'm not specifically using the MaterialComponents theme in my styles, the app will crash whenever I try to use the style on the TextInputLayout.
Is there a way of using the nice Exposed dropdown from MaterialComponents without using the entire theme (as this overrides all colors for buttons and such)? Or maybe just a simple way of getting a nice and simple dropdown otherwise. Spinners seem kinda hard to work with..
Cheers.

How to add design tab to palette in Android Studio

This is what my palette looks like, I want to know how to add other tabs like design and appCompact.
Thank you
I'm not sure I understand what you are asking. The palette cannot be modified and is a container for components such as button, texts, etc.
Please refer to this for intro into Android Development.
AppCompact is a support library that allows for themes, colors, widgets, etc. to run on earlier devices i.e. backward compatibility.
The design view is accessed through the res folder in the layout folder. By default, called activity_main.xml.
You should go through the basics of android development so you can understand the structure, components and overview of android Studio.
EDIT:
See this link which shows you how to create custom view components
Please view this link which goes over the entire overview of the UI and how to use and customise the UI layout design(Very Useful!).
The folks that works on Android Studio redesigned the Palette window in Android Studio 3.1.2. Some of these widgets have been completely taken out.
"There is a new "Legacy" section and the "Advanced" section has gone. Along with it the NumberPicker, DataPicker, TimePicker, TextClock, Chronometer and, as far as I can see, the Transitions category has gone completely along with all its widgets."
"If you rely on any of the missing Widgets then my advice is don't upgrade until a workaround has been made available. There is no word from the Android Studio team as to why these widgets have been removed and no word on how to put them back."

Android- Can we create material views programmatically?

Is it possible to create Material Design views (like button, textView, ...) programmatically?
like
AwesomeButton btnTest=new AwesomeButton (context);
i want full featured library like rey5137 but without XML usage and support old android(maybe Android 2.3 and up).
material design is all about different combinations of items in xml. you cannot design without xml. it is not java swing don't forget, whatever you want to design their base should be on drawable or layout folder, not on java code
update for the edited question
in your example, you say AwesomeButton, in order to have something like this, you need to have a library, which also has xml design file including all those fancy visual effects. If you don't design how are you supposed to create a pre-designed button.
chamran, you are making it complicated my friend, you can't design a button via code, you have to have a xml file for your own custom materials. Even the default button has a xml.

Can I edit a style dynamically?

I'm currently developing an app which should be totally customizable by endusers. Imagine the application has many activities with some TextViews, Buttons, etc.
So the client can create a XML file like this one:
<style >
<h1>25dp</h1>
<h2>30dp<h2>
<actionbar>#cecece</actionbar>
</style>
As you can imagine, for example, there are several TextViews which are always "titles" so they should always take this h1 value.
I know I can parse this XML file and for each textview, apply this style manually, but this is not a good way of achieving this because if I had 3000 textViews, I should manually edit them all.
What I want is to "edit" the actual Style programmatically.
Any tip?
You can't access a resource file in the created APK as they are compiled into it. So your idea to "customizable" styles works only in the following scenario:
your app is a library project
your client uses that library project and create a style which extends/overwrites your own style and compile that into a new APK
You are not clearly telling us if the "enduser" is a user of your app/apk or a customer that can do the above mentioned modifications.
An alternative might be to create your own extensions of TextViews, Buttons etc which can load your style set. You need to create your own style language for that and you need to make sure that the custom views understand and apply them.
A lot of work, if you ask me... I would, in general, suggest to make different themes so that the customer can pick the best suited for them...

how to change android spinner popupBackground

I was trying to change the android spinner popup window background by setting the android:popupBackground, but it didn't have any effect. Is there any way I can change it?
<Spinner
android:id="#+id/eventNameSpinner"
android:layout_width="160dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="6dp"
android:background="#drawable/btn_name"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:popupBackground="#drawable/bkg">
I presume you are trying to change the "outer" backgroud of a Spinner's popup, not the background of Spinner "pupup items". Also, I presume that by popup, you mean a Spinner's dialog mode, where a floating dialog window appears on top of your activity, as opposed to the new dropdown mode.
Strategy
For a clean, sustainable approach which behaves well across multiple Android platforms and reduces the need for redundancy in the App, I believe it is essential to understand what the official docs don't tell us. So follow me on a short journey.
The tricky part about Spinners is that an Adapter is used to connect them to data. While it is relatively easy to identify the hooks for changing the appearance of android.R.layout.simple_spinner_item and its friends, those only determine the style of the Spinner's currently displayed item as well as each single popup item. But it is the Adapter which is responsible for creating the ListView and other widgets which frame that ListView.
This complexity is probably the reason why Android has introduced some attributes which can be specified on-the-fly "for" the Spinner although they are then applied to the Spnner's children, such as android:popupBackground. This is not necessarily a clean approach, rather a limited set of convenience functions. Regarding popupBackground, btw, this was introduced in API level 1, but Spinners respect it only in spinnerMode=dropdown, which was introduced in API level 11. That's the reason why you'll never be notified if you use it wrongly.
Older Android Versions (such as 2.2)
ListView
Knowing that the Adapter creates a ListView, it's not a bad idea to change the ListView appearance in one's theme, so there's one single place for the design change and the styling straightforward, like so:
<style name="MyTheme" parent="#android:style/[reference to original theme]" >
<item name="android:listViewStyle">#style/myListView</item>
[...]
</style>
<style name="myListView" parent="#android:style/Widget.ListView">
[check Android's Widget.ListView to understand what you can change here]
</style>
AlertDialog
Unfortunately, there's more work ahead. Because android:prompt can be used to create a headline for the popup, the popup really consists of more than just the ListView.
Android uses an AlertDialog
Recent Android Versions (such as 4.2)
Now that the AlertDialogs are styled, we still have to address the fact that more recent versions of Android don't use AlertDialogs for Spinner dialogs any more. That doesn't hurt, because for those, the AlertDialog style shouldd be kept anyways. It just means we need to style the new popup as well.
To do so, create version specific theme XML files to pull the additional styles into your customized theme, and provide version specific style XML files.
Feel like trying it yourself, starting here?
android:popupBackground is only valid when using android:spinnerMode = "dropdown" , thats probably why it wasnt any effect in your code. You need to tell that spinner which mode its in with some XML.
android:spinnerMode = "dropdown"
Links
http://developer.android.com/reference/android/widget/Spinner.html#attr_android:popupBackground
http://developer.android.com/reference/android/widget/Spinner.html

Categories

Resources