Adding a button to the android emulator skin - android

I'm trying to add a button to one of the default emulator skins. I used the layout file to get the button to appear but I'm not sure how to map it so that it actually does something.

You want to grab the button from the layout XML with something like this in onCreate:
Button xButton = (Button)findViewById(R.id.buttonX); //buttonX is the id you gave the button in the layout
Then you could set a click listener for that button in your onCreate like this:
xButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// do stuff here
}});

Very late but here is what I've found:
Create your skin as normal with the button images in place (rendered)
Create a button overlay image which is going to be drawn over the button when you mouse move over it with the mouse (can be the same for all buttons given it is only meant to be a focus indicator)
In your skin define the button(s) in the layout (see below)
For each button you can link it to a specific qemu code (see https://android.googlesource.com/platform/external/qemu.git/+/8b9887163ce94928aec159956d1a61fc93bb949d/android/skin/file.c#122)
layout:
parts {
device {
...
}
portrait {
...
buttons {
search { // see qemu codes
image xxxx.png // the overlay image to show on mouse move over
x 00000 // the top-left coordinate to show the image
y 00000 //
}
}
}
}
PS: I am pretty sure the button size is dependant on the button image dimensions.

Related

android custom togglebutton border

I have a grid of 64 togglebuttons in an 8x8 form. when the app runs, it sets each togglebutton's background/drawable to a colour. this is done in the program, not the xml. my problem is that while there seems to be space between the buttons on the graphical layout of the app, when the app runs, and changes the buttons to a colour, the space disappears. this makes the buttons look like a single plate, with no definition between buttons.
What I want is to put a border on the buttons to make it clear where each button is.
the function of the buttons is to be used to indicate a musical note being pressed. when the button is pressed, the colour of the button turns from grey to light blue, and adds the note to a sequence.
So i need to be able to put a border on a togglebutton with a custom design, that changes when activated/deactivated, keeping the border in both states. i have also tried setting the max width and max height, and also setting the padding on the buttons in an attempt to seperate them.
an example of the code is as follows:
public class MainActivity extends Activity implements OnClickListener
{
ToggleButton tg1;
....
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
....
tg1 = (ToggleButton) findViewById(R.id.toggleButton1);
tg1.setOnClickListener(this);
....
tg1.setBackgroundColor(0xffcccccc); //set button grey
}
public void onClick(View v)
{
if((tg1.isChecked()))
{
tg1.setBackgroundColor(0xff00ffff); //set button blue
}
else
{
tg1.setBackgroundColor(0xffcccccc); //set button grey
}
}
}
any help is greatly appreciated.
Right way: do not call isChecked manually to change background. Use selector. You can draw 9-patch with a border or create shape (use stroke to set border color and solid to set fill color).
Or create a custom togglebutton to support desired functionality.

How can I change the name of buttons on click of a button?

In my calculator app, I want an Inverse button, which when clicked changes the text of other buttons. Like sin to sin inverse etc. Is this possible?
You can just change the text of a button in that button onclick event.
Say For example
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(btn.getText().toString().trim().equals("sin")){
btn.setText("sin inverse");
}else if(btn.getText().toString().trim().equals("sin inverse")){
btn.setText("sin");
}
}
});
I think this will help you
While the other answers are completely right showing you to how rename the buttons, I suggest another solution with a cleaner design: Have different buttons for "sin" and "sin inverse", and just make them visible/invisible when clicking the "Inverse" button. That way you can write clean click handlers and don't have to use a lot of "if (isInverseMode()...)".
To make that work correctly, you just declare some additional buttons for the inverse operations in your XML layout file and set them to android:visibility="gone".
If you then set one the visible buttons to invisible and the next insivible button besides it to visible in the code, then the effect for the user looks like you exchanged one button by the other (so he only notices the text of the button changing).
It's possible.
Just re-set the button text in your onClick method for the button.
buttonId.setText("Your button text");
From what you're saying though it sounds like you want to change the buttons function as well as the text... in which case you need to put an if statement in your onClick method to handle the two button states.
Setting the text on a button would help anytime.
This code may help you..
final Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
btn.setText(new StringBuilder(btn.getText().toString().trim()).reverse());
}
});

how to zoom-in interface? Android development

In my Android application, I have an activity with three layouts: A left layout, a middle layout, and a right layout.
The right layout is the main one. I want the right layout to zoom into fullscreen when I click a button. If you have the specific code,it's better.
Thanks very much!
If I got your question right:
Your button's OnClickListener should look like something like this:
OnClickListener listener = OnClickListener() {
public void onClick(View v){
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
};
This by itself will not get your right layout to fullscreen. You'll need to add something the below to your right layout for it to "auto fullscreen":
android:layout_width = "0dp";
android:layout_weight = "1";
if you don't do that, you'll have to resize the right layout from the "listener" above.
Hmm, the question is vague, but if I understand correctly, what you want to do is hide the left and center layouts when a button is clicked, so that the right layout becomes full-screen?
Without more details, it's not easy to give you a more precise answer (please post your current layout), but I would do something like:
// this code in your Activity:
// this method is bound to button onCLick (android:onClick="clickButton")
public void clickButton(View view) {
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
}
And to revert back to a 3-layout display, you do the opposite (View.VISIBLE)

Android: QuickContactBadge in the ListView

First the scenario:
I have a list where each item has a photo of a contact and some text. I would like to click on the image and bring up the QuickContactBadge. Badge is defined by the following XML snippet
<QuickContactBadge android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/badge"
android:layout_alignParentBottom="true"></QuickContactBadge>
What I tried and failed:
Define one reusable badge and reuse it for all cases. Both list and badge are placed into RelativeLayout
Have one badge defined per each list item. The item uses RelativeLayout
What do I see:
Basically nothing. The code gets valid badge instance and then I apply the following logic
contactPhoto.setOnClickListener(new OnClickListener() {
#Override
public void onClick(final View v) {
Log.d(TAG, "Image click");
if (badge != null) {
badge.assignContactFromEmail("johndoe#gmail.com", true);
badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
badge.bringToFront();
}
}
});
As I click I can step through the code in onClick handler yet the badge never comes up
The questions:
Does QuickContactBadge have any placement logic? When I click on the image do I need to calculate badge position and readjust or is it built-in?
Is it possible to achieve what I describe above (badge for images displayed in the list) and what I'm doing wrong (or missing)
Abort! Abort!
Basically I totally misunderstood what the badge is and how to use it. What I was trying to do is to detect click on image and call the badge. This is fundamentally wrong since all I needed to do was to simply use QuickContactBadge INSTEAD of ImageView in my code. After I replaced images with badges in the item XML magic was automatically there.
Said that - it is possible to pop the badge using the code, refer to this article on how to do it

Android onClick(View v) not working?

I'm new to Android. I'm stuck at a point and would really appreciate it if anyone could please help me. I'm developing an app which has a grid of colored rectangles. These are created by changing the background colors of a number of TextViews. There are 3 Buttons which cause the background color to change according to some algorithm. There are also 2 TextViews which show the current status of the game.
Now the problem is I have a button example (one of the three buttons) which is supposed to change the background color of the rectangles.
example.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
status_val.setText("true board-example working");
level_1_true();
}
});
The level_1_true() method sets the background color of the rectangles. The above code results in an "activity not responding" dialog being shown, and the OnClickListener does not change the view. Someone suggested I try the runOnUIThread method in activity, but I can't get it to do what I want it to do.
How do I change the view of the screen by clicking the button?
Maybe you can try adding in your button xml code android:onClick="onClickMethod" and adding in your activity
public void onClickMethod(View v) {
status_val.setText("true board-example working");
level_1_true();
}
How did you define status_val? You remeber to link it like this?
status_val=(TextView)findViewById(R.id.);
Please tell me if I can be of more help

Categories

Resources