imagebutton

How to switch button image from on to off and vice versa upon click?

北战南征 提交于 2019-12-06 00:22:05
I have been trying to switch the state of my buttons from on to off and vice versa, by adding an image for on and adding an image for off state. I tried through xml, however I was just able to temporarily switch it upon click (by using press/focus etc). Here is the code for the same: fragment_justin: <RelativeLayout android:id="@+id/top_bar_container" android:layout_width="match_parent" android:layout_height="48.5dp" android:layout_alignParentTop="true" android:background="@color/background_action_bar" android:orientation="horizontal" > <ImageButton android:id="@+id/menu_button" android:layout

ImageButton: Force square icon (height = WRAP_CONTENT, width = ?)

吃可爱长大的小学妹 提交于 2019-12-05 22:44:05
问题 In my horizontal LinearLayout I have a TextEdit and an ImageButton. The ImageButton is as high as the TextEdit. I'd like that the ImageButton is exactly as wide as it's long. At the moment it looks like the width of the ImageButton is like when there is no scaling (ImageButton width [px] = unscaled drawable width [px]): <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/txtName" android:layout

Android ImageButton worked well in Activity. It doesn't work in Fragment

百般思念 提交于 2019-12-05 19:28:30
I'm trying to convert a layout so that it will include fragments. One of the views is an ImageButton that has a listener. The code worked fine as an Activity but makes trouble as a Fragment... First problem was that I couldn't use findViewById, but I was able to find the answer for that here and fixed it with getView(). I can't find an answer to the second problem... after I declared: ImageButton camBt = (ImageButton)getView().findViewById(R.id.button1); I want to set an on click listener: camBt.setOnClickListener(listener); But it keeps acting like the ImageButton (camBt) doesn't exist... I

How can I change the images on an ImageButton in Android when using a OnTouchListener?

本秂侑毒 提交于 2019-12-05 14:56:22
问题 I have the following code which creates an ImageButton and plays a sound when clicked: ImageButton SoundButton1 = (ImageButton)findViewById(R.id.sound1); SoundButton1.setImageResource(R.drawable.my_button); SoundButton1.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN ) { mSoundManager.playSound(1); return true; } return false; } }); The problem is that I want the image on the ImageButton to change

Error No resource found that matches the given name (at 'src' with value '@drawable/button1')

纵然是瞬间 提交于 2019-12-05 12:57:04
I thought the book had incorrect code. Tried at my home location and it worked. Found out that my eclipse was actually broken. Had to remove and re install eclipse. This is my first post here so if I didn't follow some of the rules please let me know. I tried to search and found a few post with the same error but they dealt with strings. I'm following Android Apps for Absolute Beginners (2nd Edition) and on page 179 you bring button1.xml into your res/drawable. When I go in layout/activity_main.xml and input <ImageButton android:id="@+id/button_one" android:layout_width="wrap_content" android

android ImageButton gets gray background

大憨熊 提交于 2019-12-05 12:23:34
i have a Button with a nice background selector. fine. in stead of text in the button, i want an image. i have tried just changing it to an ImageButton with a src attribute. when i do this, it looks like a gray background is overlaid behind my selector, behind the src image. when i change back to a regular Button, the problem goes away. what i want is just my background selector, plus the src image (in stead of the button text). any ideas? kdumitru ImageButton should have android:background set. <ImageButton android:id="@+id/ibArrow" android:layout_width="35px" android:layout_height="50px"

JavaFX drop down button

孤街醉人 提交于 2019-12-05 11:15:24
How can I create a "Drop down button" in JavaFX? So far i was using a ChoiceBox for the purpose , now that I have to assign an image to the ChoiceBox , ChoiceBox.setGraphic() // is not available as like Buttons So I am planning to change it to a drop down button. So that i can set an icon to it. Am using SceneBuilder for designing UI. No help in searching how to create a drop down button using JavaFX. If you do not have to store the selection like in a ChoiceBox you can use for example the MenuButton control. MenuButton is a button which, when clicked or pressed, will show a ContextMenu. A

OnClickListener cannot be resolved to a type (Eclipse)

喜欢而已 提交于 2019-12-05 05:43:40
Hello im new to programming, im trying to construct my first simple application, im looking to play a short soundclip on the push of an ImageButton. while typing out my code i get an error with the statement; Button.setOnClickListener(new OnClickListener() { The on click listener is underlined and when i go to the error eclipse tells me that OnClickListener cannot be resolved to a type. Here is my code: import android.app.Activity; import android.os.Bundle; import android.view.view; import android.view.view.OnClickListener; import android.widget.Button; import android.widget.ImageButton;

How do I programmatically change the ImageButton src target when a condition is met?

隐身守侯 提交于 2019-12-04 23:36:45
I have a school project where I am trying to get a flashlight app going. For the on/off ImageButton, I want to have 4 custom images. If flashlight is off: -turn_on.png (default) -turn_on_pressing.png (state pressed = true) If flashlight is on: -turn_off.png (default) -turn_off_pressing.png (state pressed = true) I am hoping to change the ImageButton src target to change between "on_selector.xml" and "off_selector.xml". Originally I was able to setImageResource() to change the default button images. And now that I am trying to add my own on press images, I am having a very difficult time.

Array of ImageButtons, assign R.view.id from a variable

这一生的挚爱 提交于 2019-12-04 18:54:28
问题 Hey there. My app is going to be using an array of 64 ImageButtons (8x8), and they're all already declared in my XML Layout with names like one1, two5, eight8, etc. Rather than declare these each individually in my Java I thought it might be smart to declare them all in some for loops. I have ImageButton musicGrid[][] = new ImageButton [8][8]; Then I have my nested for loops that basically create a string that will be in place of R.id.whatever. It's just that last line in my loops, that is