I want that my button looks like a spinner, because I will show a special dialog if the button is clicked. I use Theme.MaterialComponents and tried following but it's not working:
<Button
android:id="#+id/btMusclegroups"
style= "?spinnerStyle"// or style="#style/Widget.AppCompat.Spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
The button still looks solid and not like a spinner.
Desired result
I want that my button looks the same as following Spinner:
<Spinner
android:id="#+id/btMusclegroups"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I could use a Spinner with OnTouchListener and a dummy adapter (I don't need the adapter, my dialog knows all the data it needs already) but I'd prefer the above way - is this somehow achievable?
Create a container and add an image view containing the dropdown symbol for the spinner and a button. Add an OnClickListener to the button that calls the dialog and updates the text of the button. Don't forget to style the button as NoBackground.
Related
I have a button Add new address and when it is pressed, I want to show EditText fields to collect the new address details. Is there any layout to do that. Or hiding the text fields when the Button is unpressed, is that the only way to do this?
Define the edit box in a layout as below -
<LinearLayout
android:id="#+id/exp_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/exp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
/>
</LinearLayout>
And now use the layout id to get the view like below.
LinearLayout l=(LinearLayout)findViewById(R.id.exp_linear_layout);
And just toggle the visibility on button click event -
l.setVisibility(View.GONE) and vice versa.
I hope it will help u.
There is no built in framework to do it. You can do this by setting View.SetVisibility() to visible or gone. Initially the button is visible but textfield is invisible. When user click on the button, you can set this button visibility invisible or gone and visible the text fields.
I have created custom tab bars by following the post given below:
How to create a Tab-like UI in Android?
No I need to display a set on sub menu when the center tab (actually it is a button) is clicked. I need the sub menu to pop up like in this drawing (sub menu should be above my main layout):
I believe that this can be achieved by putting an additional layout above the custom tab bar in which a set of buttons can be placed one after another. But I am not sure which layout needs to be used and how I can get the same style in the drawing. Please help me to find a solution.
you're correct with just adding another layout above the button you want to open it, and then setting its visibility to gone until you want to animate in it.
a regular LinearLayout would work fine, and then adding 4 buttons to it would work as well, then you would want to make sure those buttons used the same styles as the built-in android menu buttons (or style it yourself) but check out some of the built in styles here
example:
your activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
//all your other activity layout stuff goes here
<!--add your new menu-->
<LinearLayout
android:id="#+id/my_menu_layout"
android:visibility="gone"
... />
<Button
android:id="#+id/menu_btn_1"
style="#android:style/Widget.Holo.ActionButton.TextButton" //as example of built-in style
... />
//more buttons
</LinearLayout>
then in your activity class, assign an onClickListener to the button that will toggle the menu and animate the view in
//animation xml you make
Animation inFromBottom = AnimationUtils.loadAnimation(this, R.anim.layout_in_bottom);
mMenuLayout.startAnimation(inFromBottom);
mMenuLayout.setVisibility(View.VISIBLE);
now your view will animate in and you can go about adding onClick listeners to the buttons
I'd like to insert a progress spinner in AutoCompleteTextView while another class performs the autocomplete function.
I read about the frame Layout ed fixing it in the EditText but the question is:
How to set the progress spinner? And how to control it?
Use this in the layout where you want to display the ProgressBar. You can set the visibility, View.VISIBLE, View.GONE to make it visible and invisible.
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />
In my Android app, I have a GridView layout with a set of Buttons. The problem is, that I can't set properly the focus (I mean cursor, controlled with joystick on the Android device) on the buttons. I can describe my problem with a picture:
I set the Buttons to the GridView dynamically in the code in BaseAdapter using LayoutInflater. In the code, I set button's text, image (CompoundDrawable) and background color, because my buttons works like a checkboxes (blue background means checked).
It seems like the program is focusing the grid field and not the button itself. I mean something like cell of table and not the button in table. Because the focus color is default (green) however I set the blue color in selector. Focus press also doesn't work. And the focus is evidently behind the button, out of button's bounds. Can somebody help me with this trouble please? Code of my XML layouts:
main.xml:
...
<GridView
android:id="#+id/channels"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dip"
android:verticalSpacing="10dip"
android:horizontalSpacing="10dip"
android:numColumns="auto_fit"
android:columnWidth="60dip"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#color/container_main">
</GridView>
...
channel.xml:
<Button
android:id="#+id/channel"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:background="#color/willBeSetInAdapter" <!-- white/blue/darkblue focus background -->
android:drawableTop="#drawable/willBeSetInAdapter" <!-- icon -->
android:drawablePadding="0dip"
android:text="WillBeSetInAdapter" <!-- label text -->
android:textColor="#color/text_container_main"
android:textSize="12sp"
android:focusable="true"
android:focusableInTouchMode="false">
</Button>
I tried to set focus parametres in Button and also in GridView and tried a lot of things, but unfortunately it still doesn't work :(
Setting android:descendantFocusability="afterDescendants" for GridView solved my problem. Because program focused the grid field and not the button itself. Using descendantFocusability parameter I forbid to focus grid field and allow only to focus the buttons.
Have you tried setting android:drawSelectorOnTop="true" for your GridView?
Iamtrying to have a button at the bottom of the list, so when u scroll down and the list has ended than there will be a button "Get more", which will populate the list with more items.
But the button is not visible. this is how my xml file looks like.
Maybee this occurs because of the scroller,, maybe the scroller only works for the list.
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button android:id="#+id/search_browser"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Get more ads" />
</LinearLayout>
That's not really the correct way of doing it.
In your case, the button will ALWAYS be visible at the bottom of the list.
If you want it to be visible only when user scrolls at the bottom, use:
yourListView.addFooterView(someFooterView)
This footer view can (logically) be any view (button, layout), inflated, or created at runtime.
P.S. http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
P.S.S. In your case, you need to remove your button declaration in XML, leaving only ListView.
And in code do
Button button = new Button(this);
button.setText("Get more ads");
((ListView) findViewById(R.id.list).addFooterView(button);
Try the following:
android:layout_height="0dip"
android:layout_weight="1"
instead of
android:layout_height="fill_parent"
for your ListView.
I believe however that is more appropriate to have an auto-growing list.