I have a simple soundboard which uses Buttons to represent the sounds. When a sound button is clicked. The background image is changed using the view.
Button butt = (Button)view;
butt.setBackgroundResource(buttons_on[media]);
buttons_on is a int[] representing the drawables of the buttons.
This all works perfect, but I also use a FragmentActivity to create a paged App. The App has 4 different pages which you can swipe through. When I change a button using the above code and swipe two pages to the right and than swipe back. The image of the button has changed back to it's default defined in the page.xml.
How can I prevent this behavior?
change the Buttons to ImageButtons and setting the src?
somehow prevent the page from reloading
Instead of doing that you should look at how to use a StateListDrawable. It will simplify your approach.
Related
enter image description here
Should I use fragments? but I want an overlay over the map activity. How can I achieve this?
So far, I have been trying, to add two buttons and on click of a button opens a floating map, but it doesn't give me this result, it resembles a bookmark bar on chrome with three dots on the sides which aren't what I want.
Not sure what you are going to do when user will tap on go back or any button or back press
but here i assume it that you are going to remove that white overlay and only map will be shown
if yes then you can simply use map in your activity/fragment whatever you like and white overlay should be created and shown using BottomSheetDialogFragment
to understand how you will create BottomSheetDialogFragment , you can refer this example
https://medium.com/#kosta.palash/using-bottomsheetdialogfragment-with-material-design-guideline-f9814c39b9fc
I think the best bet is using coordinatorLayout with a child layout that has BottomsheetBehaviour for the overlay. or simply BottomSheetDialogFragment if user isn't going to interact with map when the overlay is drawn up.
a layout with app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" fits the picture. more on that here
Hello I have some questions for adding images for a ImageButton.
I have an icon for example a play button now if I hover over the button it just should get a blue surounding box the inside Image should not change.
Should I draw for every icon the two states or are there other options.
If an button is not clickable it should get Grey. Same how to do this? Add an additional Image to every Icon?
For what is the Checked drawable in the ImageButton?
ImageButtons have a drawable for their background (up, down, over, etc.) and a drawable for the image on top of the button (imageUp, imageDown, imageOver, etc.). The only ones you must provide are up for the background and imageUp for the icon. These are the defaults used when you leave the other states null. But for visual reasons, you need down for the background or it will be hard to tell if the button is being pressed. It's up to you whether you think you need to also change the icon appearance with an imageDown.
All you need is to add the background drawable for disabled. If you want the icon to also turn gray, you need to create a gray version of the icon and assign it to imageDisabled.
The Buttons in Scene2d all support toggle functionality. When you press it, it will toggle to the checked state, so you can use the checked drawable to change its appearance while it is stuck down. If you don't want that to happen, leave the checked drawable null.
I am designing my activity screen using eclipse but whenever I move an object e.g. a button it snaps around and I find it hard to position things where i want them.
Is there some setting I can change as as soon as I add a second button it snaps the other button to another position it is so annoying!
Also if I have an image button why can't i resize this, even with a normal button if i try to make it larger it just fits to the text and wont make the button bigger or it just flicks to a random place on the activity?
thanks
Probably you're trying to place components freely in the View but you're not considering the LayoutManager behavior. If you try to position your component in a LinearLayout, for example, the components will be placed following its rules, and these components will not stay where you drop them.
Try to understand better how the layouts works on Android. But for now, the AbsoluteLayout or RelativeLayout may be what you're looking for.
About the components size, you'll need to understand better how to use layout properties for these components. See the question How to size buttons for more information.
I am thinking about making a launcher for android, i dont know if i'll market it. But i'm thinking like my phone is in landscape mode, and i see 4 rows of buttons, and 4 buttons on each row. Kind of like a grid with buttons. And then, once i click a button, i want the buttons splitted in the middle and moved from each other, with an animation. And then a second screen comes in from the back. How can i do this? I thought of creating two layouts holding 4 buttons each, and once i click one, it should move the layouts from each other and the second blank screen would kind of fly in from the back, like if it was behind the buttons. How can i create these animations? Please help me and thanks so much!
You can add a middle row with width initially as 0dp, and then when opening an Activity you could animate its width, and for the second screen you can use a simple zoomIn animation with overridePendingTransition() after startActivity()
Is there any way I can make two buttons appear up and have the main UI greyed out without calling the pause method in android? sort of like robo defender. thanks!
I'm unfamiliar with Robo Defender, but a common way to do this sort of this is with an overlay. You can put a view over your activity with an opacity of ~30%. This view can have a grey image that cover everything but your buttons.