I know this question is repeated but I don't get the Proper solutions.
I want to bring arrow closer to the Spinner (That means i want to decrease the width of spinner and decrease the space between text and down arrow) I have used default spinner. How can I do that? Please, guide me to get Solution.
Here is the XML code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/relativeLayout15">
<Spinner
android:id="#+id/languageDropdown"
style="#style/SpinnerTheme"
android:layout_width="66dp"
android:layout_height="wrap_content"
android:entries="#array/Languages" />
</RelativeLayout>
As i am understanding your question, many time we face requirement to customise spinner UI and it is too tough to achieve this. I generally use this solution for such situations:
Solution: Hide your actual Spinner and show a TextView which just looks like our desired Spinner, Please have a look at below image for better understanding:
In above image I have created a phone number field where I am getting country code from user using Spinner. I created a TextView having text as country code with drawable[right] of down arrow. Please check below XML code for better understanding:
In above image Spinner width is 0dp so your Spinner will not be visible. Just remember one thin you have to handle click event of TextView and call performClick() method for Spinner. Please refer below image for this code:
On the click event of your TextView, just follow below way:
textViewLabelCodeRegister.id -> {
spinnerCountriesRegister.performClick()
}
That's It.
Make PopupWindow instead of Spinner.
Related
I've tried a tutorial on youtube but it doesn't work,when I click the button nothing happens.
When I press the button I want to Change the layout activity and also to be set on the new layout one random text from lets say other 10 and on this current layout I wanna have the button which will randomly change the first text to another one.
Here is what codes I've used and didn't worked out.
#I can't add the codes because It doesn't let me post it here..it says something like isn't valid but you see everything in the picture,so I did all that code and when I press on my button It doesn't doing anything,what can be the problem?and If you have any idea or if you know any tutorial to help me achieve what I said I want to do upper I would appreciate really much
#as you can see there is a string option which should give me one text of all of them when I click my button,but it doesn't
sorry for image but it seems like those codes aren't good
<LinearLayout
android:layout_width="332dp"
android:layout_height="184dp"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:layout_marginTop="48dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/buttonsports"
android:layout_width="match_parent"
android:layout_height="129dp"
android:background="#drawable/ft"
tools:layout_editor_absoluteX="115dp"
tools:layout_editor_absoluteY="291dp" />
<TextView
android:id="#+id/sports"
android:layout_width="216dp"
android:layout_height="117dp"
android:text="TextView"
tools:layout_editor_absoluteX="95dp"
tools:layout_editor_absoluteY="246dp" />
</LinearLayout>
this is how big my text box is,the "sports" is the id for TextView which is "abc"
In your xml you have a LinearLayout for which you have set the height to:
android:layout_height="184dp"
and inside there is a Button with height:
android:layout_height="129dp"
So for the TextView below there is left maximum 55dp but you set:
android:layout_height="117dp"
This means that at least half the TextView is not visible.
In your code you set a random text to the TextView when you click the Button.
You say that nothing happens.
Is there a case that the text is being set but you can't see it because the TextView is mostly hidden?
Change the heights of the views and you will find out.
I'm trying to make an app like the one in this mockup:
Supermarket
It's a very simple supermarket app. As you can see, there's a TextView at the bottom of the screen that tells me whether my Cart is empty, or has items in it. If the cart is not empty, the user is shown the total price he/she must pay. You can also notice that said TextView's style and text change according to a variable (in this case, "totalPrice").
How can I do this in Android? I know I can use simple if statements (if totalPrice == 0, then backgroundColor = grey and text = "EmptyCart", for example), but this seems somewhat... hardcoded. Is there a better way to do it? As you can see, the TextView's style and values also change when on the "Subproducts" activity (some Products have Subproducts, which you can see after clicking on them).
Thanks in advance!
I think Databinding is the best way rather than boilerplate code.
create a model class and change background of the view using ternary operation in databinding also manage visibility of price text using this.
To set a textview's text, you use textView.setText("new text"); To set its background, its textView.setBackgroundColor(color) where the color is the hexcode you want as an integer- for example 0xFFFF0000 for reg. Obviously these can be variables as well as hard coded.
It can simply be achieved with two TextViews in a RelativeLayout, and of course, by using basic TextView's methods. As an example layout:
<RelativeLayout
android:layout_height="75dp"
android:layout_width="match_parent"
android:background="#1EC4F3">
<TextView
android:text="PAY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:typeface="sans"
android:textColor="#FFFFFF"
android:textSize="18sp"/>
<TextView
android:layout_height="wrap_content"
android:text="$25.79"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:typeface="monospace"
android:textSize="14sp"
android:textColor="#FFFFFF"/>
</RelativeLayout>
I would like to figure out if it is possible to make Dropdown (Arrow) Logo of a Spinner smaller.
See my two screenshots please:
The first Screenshot shows that Dropdown label is pretty big.
The second shows what I really want to accomplish. It is not about the Dropdown, I want to have the ability to have more text when a item is already selected.
This is what I use as code:
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/heroSpinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="15sp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="10sp"
android:autoSizeMaxTextSize="15sp"
android:dropDownWidth="match_parent"
android:popupBackground="#8A8A8A"
android:spinnerMode="dropdown" />
Can edit my mainActivity and Adapter if needed.
Can someone help me please? :)
[You can perfectly see the problem here, the drop downlist opens from the top of the spinner and not from the bottom and I don't know what to do, couldn't find any solution on google either, please help me] sorry for external image link, for some reason it wont load the picture here..
here is my spinner code:
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rgGender"
android:entries="#array/months_array"
android:textAlignment="center"
android:id="#+id/spMonth"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"/>
This would happen if the item which inflates the spinner is close to the bottom of the screen.
Since the spinner would not have enough room (or just barely enough room) if inflated downward, it is inflated upward instead. Try putting the spinner higher (vertically) in the layout.
It depends on Screen size, If you test it on other device it will show at down/up.
I suggest you to test it on different devices.
you can use custome adapter if you want
<Spinner
...
android:overlapAnchor="false" />
Please check this answer and this answer
I have two EditText views on a layout containing a date and a time. On being clicked these open up my custom DatePickerFragment and a TimePickerFragments. I would like to style the EditTexts with a picker drop corner as the following image shows.
however I have not been able to do this, my text fields look like this:
The pickers all work and are hooked up and return values to the EditTexts, I just want to do the styling correctly. I am happy to change the class of the containers from EditText if they should be something else to get the desired behaviour. I think this should be possible as the first image comes from Google's own design documentation. Looking through the EditText and TextView class documentation and xml attibute documentation. Is there a way to do this?
I am using Xamarin to compile this down but that should make no difference to the answer.
set the Style attribute to the following:
<EditText
style="?android:attr/spinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
use following image as background of your edittext
make it 9 patch with whatever colour you want.
find an original image and Create a nine patch image like below..
Note : Black Lines are patches
And then add image to background of EditText like below..
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/box_edittext"
android:padding="10dp" />
OR
You can use this simple way...
Define style="?android:attr/spinnerStyle" to EditText..
<EditText
style="?android:attr/spinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>