Android :: Adding Image For Button
Nov 17, 2010How to add an image to appear in button in android rather than a text ??!
View 1 RepliesHow to add an image to appear in button in android rather than a text ??!
View 1 RepliesCan anybody please guide me how to write the code for opening the new image after clicking the imagebutton in android. I have tried something like this:
package com.example.imageButton;
import android.app.Activity; import android.os.Bundle;
import android.view.View; import android.widget.ImageButton;
public class imageButton extends Activity {
private static ImageButton seqIBtn;//these are the three imageButton private static ImageButton vidIBtn;private static ImageButton infoIBtn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); seqIBtn = (ImageButton) findViewById(R.id.btnSequence); vidIBtn = (ImageButton) findViewById(R.id.btnVideo); infoIBtn = (ImageButton) findViewById(R.id.btnInfo);}
I want to put "Go" button in android application softkeyboard for search and other related scenarios can any one guide me how to achieve this? with example.any help would be appreciated.
View 3 Replies View RelatedI was wondering how we could add objects such as textview and radio buttons to the activity through code and not the XML file and still have it run correctly. I tried adding a simple textview below but I got an error when I tried to run. Can any1 tell me how I could add the textview in correctly? import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.widget.ScrollView; import android.widget.TextView;public class Q_end extends Activity { /** Called when the activity is first created. */ private ArrayList<String> qs = new ArrayList<String>(10); private ArrayList<String[]> as = new ArrayList<String[]>(10); @Override public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); setContentView(R.layout.end_app); ScrollView we = (ScrollView) findViewById(R.id.viewer); String[] temp = new String[4]; temp[0] = "the"; temp[1] = "the1"; temp[2] = "the2"; temp[3] = "the3"; as.add(temp); String temp2 = "the rocks says"; qs.add(temp2); qs.add("the question is"); String[] temp3 = new String[1]; temp3[0] = " "; as.add(temp3); TextView gg = new TextView(null); gg.setText(qs.get(0)) we.addView(gg);
View 4 Replies View RelatedI want to create a layout in such a way that on top edittext and button should be there in one row. The search text I enter in editext and click on search button. Then I want to display a custom list view where each row contains image and text.(As per the API demos example list14 I have tried). But when I run the application, button and edittext are being added to each row (i.e., Each row contains a image, text, editext, button.
Below is my xml file:
<!--
<FrameLayout android:layout_width="wrap_content"
android:layout_height="0dip" android:layout_weight="1"></FrameLayout>
-->
<ImageView android:id="@+id/icon" android:layout_width="48dip"
android:layout_height="48dip" />
<TextView android:id="@+id/text" android:layout_gravity="center_vertical"
android:layout_width="0dip" android:layout_weight="1.0"
android:layout_height="wrap_content" />
<!--
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/prdsearchtb"
android:text="@string/tb_prd_search_lbl"></EditText>
-->
<!--
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"> <TableRow>
-->
<Button android:id="@+id/prdsrcbutton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/btn_lbl_prd_search"
android:layout_x="2px" android:layout_y="410px"></Button>
<!-- </TableRow>
</TableLayout>
-->
and Java File:
/**
*
*/
package org.techdata.activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
/**
* @author jayanthg
*
*/
public class ProductSearch extends ListActivity {
private static class ProductSearchAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Bitmap mIcon1; private Bitmap mIcon2;
public ProductSearchAdapter(Context context) {
mInflater = LayoutInflater.from(context);
// Icons bound to the rows.
mIcon1 = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon48x48_1);
mIcon2 = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon48x48_2);
} @Override public int getCount() { return DATA.length;
} @Override public Object getItem(int position) { return position;
} @Override public long getItemId(int position) { return position;
} @Override public View getView(final int position, View convertView,
ViewGroup parent) { ViewHolder holder; Button btn=null;
if (convertView == null) { convertView = mInflater.inflate(R.layout.productsearch, null);
// Creates a ViewHolder and store references to the two children
// views // we want to bind data to. holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
btn=(Button)convertView.findViewById(R.id.prdsrcbutton);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView. holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
holder.text.setText(DATA[position]);
holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
holder.icon.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Log.i("image", " u clicked on icon Position" + position);
} } );
holder.text.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Log.i("Text", " u clicked on text Position" + position);
} } );
btn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Log.i("Button","U clicked on button");
} } ); return convertView;
} static class ViewHolder { TextView text; ImageView icon;
} private static final String[] DATA = ListView product_search_list;
Button srch_btn;
EditText srch_text; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ProductSearchAdapter(this));
// setContentView(R.layout.productsearch);
// getListView().setEmptyView(findViewById(R.id.text));
// srch_text = (EditText)findViewById(R.id.prdsearchtb);
// srch_btn = (Button) findViewById(R.id.prdsearchtb);
// srch_btn.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// callProductSearchAdapter();
// }
// });
} void callProductSearchAdapter() { setListAdapter(new ProductSearchAdapter(this));
} private void createDialog(String title, String text, final Intent i) {
if (i == null) { AlertDialog ad = new AlertDialog.Builder(this).setIcon(
R.drawable.alert_dialog_icon).setPositiveButton("Ok", null)
.setTitle(title).setMessage(text).create();
ad.show();
} } }
Every time I try to add a contact icon (from a saved image on my phone), my Magic saves a low-resolution version of the crop I make.
When I dial the contact, the picture looks HORRIBLE (it seems like the resolution is about 50x50px or something). I tried making contact icons from photos made with the phone or from high-res images that I transferred from my PC, but the outcome is always the same: the resolution of the icon is too small.
Is there a way to solve this problem? There's no point having a low-res image in a high-resolution image placeholder.
Recently I've ordered a Cube U9GT5 tablet and so far it's great, however I miss a small feature and really makes the life easier, and that is the button to kill all apps in Recent Apps window. I have this feature on my I9000 running GamerzROM (4.2.2) and I really miss it on my tablet.
The Cube is also running on 4.2.2 and is rooted. Is there any tweak or an app that can add this button?
I'm new to Android application development. I would like to ask the use of image button in Android programming when simple button can also add the image with the button. How can we generate click event of image button?
View 2 Replies View RelatedI'd like to know how to make a button out of a PNG and display it on my canvas (using drawBitmap?). When I click on this button, it will take me to a new activity. All this will be in the onClickListener. So, how do I take a PNG, make a button with it, and draw it on my canvas? I looked at ImageButton, but I'm unsure how it works or how to draw it on the canvas.
View 5 Replies View RelatedHow can i set the button to show a different image after it's been tapped? Either a different image, or maybe some kind of highlighting that shows the button was tapped.
View 1 Replies View Relatedeach child is horz linear layout w/ 3 children: image view, linear layout container and then an image button
if the image button is GONE - then i get click notifications when someone clicks on the list entry. if the image button is VISIBLE (even if i don't intercept onclick) - i don't get the list click event notification.
Is there a way to create Buttons that contain both an Image and Text (image on top text below or image left and text right)? And how can this be done within a xml layout file? For example, the application 'Pkt Auctions eBay' (see Android Market) has these type of buttons.So far I have tried and googled all over and found nothing on the matter. Help is much appreciated. Thanks in advance.
View 3 Replies View Relatedi have a nest button on clicking which a new image should be displayed.But not happening so i have taken an integer array as: private int imageCounter = 0; private int index_count = 0; private ImageView imageView; private int[] imageArray = {R.drawable.image_w_lbl_0, R.drawable.image_w_lbl_1,};
View 3 Replies View RelatedI wants to implement fading/floating of buttons like that of MediaController play/pause buttons if screen is not touched for 'n' sec.Is it possible for me to implement this on my custom image button?
View 1 Replies View RelatedI have three images in my drawable folder, and an XML Image Button code:
CODE:.............
In my layout folder, I have my main XML:
CODE:...................
When I run it in the emualtor I only get the first image. It doesn't do anything else.
I want to set a specific image when my button is not clickable. This button image is already selected according focused and pressed state thanks to this xml:
But I do not know how to define a new image for the button when it is not clickable.
How can i place a Image Buttons on the Image View. If i click the grid view i vl get a image in full screen i want tplace the imagebuttons on the images how can i place that.
View 5 Replies View RelatedA 'Button' view comes up with text, while the 'ImageButton' widget comes up with an image but no text, is there a way to relatively easily (e.g. method calls, say), either:
1. Add text to ImageButton (like those buttons that appear in menu item/via the physical menu button)?
2. Add an icon/image to a Button?
without resorting to constructing a new button class? I.e. I could put text within the image, but then I can't use Localization properly/effectively.
I'm trying to have an image (as the background) on a button and add dynamically, depending on what's happening during run-time, some text above/over the image. If I use ImageButton I don't even have the possibility to add text. If I use Button I can add text but only define an image with android: drawableBottom and similar XML attributes as defined here.
However these attributes only combine text & image in x- and y-dimensions, meaning I can draw an image around my text, but not below/under my text (with the z-axis defined as coming out of the display). One idea would be to either extend Button or ImageButton and override the draw()-method. But with my current level of knowledge I don't really know how to do this (2D rendering). Maybe someone with more experience knows a solution or at least some pointers to start?
How can I change the background of an ordinary Button into some other image(not just a color change)? ->And about Nine patch bitmap, how to use them, how to create such bitmaps and how can i convert my image into a StateListDrawable, so that I can apply it as my Button background?
View 3 Replies View RelatedHow to align an image button bottom right. My code is as follows:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal" android:background="@drawable/help"
I created a button and set the background image on it.How can I set the text below the graphic to sit on the bottom but not on top of the graphic?
View 4 Replies View RelatedHow could i get an image and a text from the Internet and made a button for my android application dynamically?And draw them in the position i want. i.e by Java code
View 1 Replies View RelatedI need button that has a replicated background pattern and normal button text on top - how to specify this in layout XML?
View 2 Replies View RelatedFor bitmap image..this code is not working
CODE:...............
I want to assign an image to one of the buttons in my activity??
how do i do that??
and for that where shall i place image.jpeg or any othr image file??
Creating a game in Android using multiple Buttons to display an image from the drawable folder. I want to change the button to a different image after the button has been clicked on.
Here is the button code:
CODE:.............
I can't find anything about how to change the actual image of the button. You can change the color of the button by using the following code in the java file: b36.setBackgroundColor(0xAA00AA00);
In my Android project,I've a image button whose background is set to some image.I want so set some text on the image button.How do i do that?I want to set the text because localization would be used in the project.
View 1 Replies View RelatedI have an image button as defined below.
CODE:...................
I want to set the default state of the button to be selected. So in code I would say:
CODE:.....
Is it possible to do this in xml?
I have an array of buttons. (calendar) now i know i set the background with a drawable. fine. but HOW can i create a image (best a nine png (so its stretchable) lets say with 3 rows each a different color) and finaly set it as a drawable? a short demo would be great
1. create simple image (3 rows with different color)
2. assign this image to a button