Tag Archives: button

943 views

View getId is null Android

If you create a button or view programmatically with OnClickListener you can set a tag key before button in parent layout is added. And get correct button by this tag getTag() instead getId() in OnClickListener etc. Button button = new … Continue reading

Posted in Android Examples Code | Tagged , | Comments Off on View getId is null Android
4,569 views

Font Family change on View dynamically Android Example

TypeFace, setTypeface, font, font family, array of String, Button create dynamically @Override protected void onStart() { LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( 48, 55 ); Typeface typeFace = Typeface.MONOSPACE; String [] ar = {"A","B","C","D","E","F","G","H","J","K"}; for (int i = 0; i < … Continue reading

Posted in Android Examples Code | Tagged , , , | Comments Off on Font Family change on View dynamically Android Example
8,512 views

How to programmatically set the button style – Android

How set rounded corners and own styles ActivityMy.java Button btn.setBackgroundResource(R.drawable.back_button_answer); \res\drawable\back_button_answer.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="10dip" /> <!– background –>   <gradient android:startColor="#D6D7D6" android:centerColor="#E2E2E2" android:centerY="0.75" android:endColor="#D6D7D6" android:angle="270" />   <stroke android:width="2dip" android:color="#fff"/> </shape>

Posted in Android Examples Code | Tagged , | Comments Off on How to programmatically set the button style – Android
8,323 views

Horizontal marquee text in Button android example

If a button have focus, marquee will run. Important: android:singleLine=”true” android:ellipsize=”marquee” Optional: android:marqueeRepeatLimit=”1″ // main.xml <Button android:layout_width="150dip" android:layout_height="wrap_content" android:text="My button with a long text for marquee as a example source code" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="1"/>

Posted in Android Examples Code | Tagged , , | Comments Off on Horizontal marquee text in Button android example
8,225 views

Android button text alignment left right – sample

android:gravity=”left|center_vertical” or android:gravity=”right|center_vertical” <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left|center_vertical" android:paddingLeft="20dp" android:text="My Button" />

Posted in Android Examples Code | Tagged , , | Comments Off on Android button text alignment left right – sample
12,635 views

Create Button and TextView dynamically – Android sample

public class MainActivity extends Activity {   @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);   LinearLayout layout = (LinearLayout) findViewById(R.id.layout); TextView textView = new TextView(this); textView.setText("Text View "); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); layout.addView(textView, p);   … Continue reading

Posted in Android Examples Code | Tagged , , , | Comments Off on Create Button and TextView dynamically – Android sample
6,415 views

Open url with browser if button clicked Android example.

Button, setOnClickListener, Intent.ACTION_VIEW, startActivity Android example.   Button mIdButtonHome = (Button)findViewById(R.id.idButtonHome); mIdButtonHome.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent browserIntent = new Intent( Intent.ACTION_VIEW, Uri.parse("http://android.okhelp.cz/category/software/")); startActivity(browserIntent); } });

Posted in Android Examples Code | Tagged , , , , | Comments Off on Open url with browser if button clicked Android example.
24,030 views

ImageView change image Android example

How to change the image dynamically in ImageView and button setOnClickListener Android sample. Main.java   ipackage cz.okhelp.my_game;   import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView;     public class Main extends Activity { private ImageView … Continue reading

Posted in Android Examples Code | Tagged , , , | Comments Off on ImageView change image Android example
2,268 views

Button Android

Google Android button example source code for developers. // get handle Button myButton; myButton = (Button)findViewById(R.id.idMyButton); //set focus myButton.requestFocus(); // set background image myButton.setBackgroundResource(R.drawable.backImage); // or myButton.setBackgroundDrawable(getResources().getDrawable( R.drawable.someImage));   // set visibility myButton.setVisibility(View.INVISIBLE); // VISIBLE   ///////// SET LISTENER Button … Continue reading

Posted in Android Examples Code | Tagged , , | Comments Off on Button Android