android - Button Control? -


so i'm pretty new @ whole development thing android , don't know slick of java. i'm tryin teach myself thought great resource. i've read devoloper.android resources , still dont understand here question. i'm making simple app change background color when button pressed. how make button that?

any outside resources/examples appreciated

here code far:

introactivity.java

 package com.flashcalc;  import android.app.activity; import android.os.bundle; import android.view.view.ontouchlistener; import android.widget.button;  public class introactivity extends activity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);      } } 

main.xml

   <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="@color/all_white"> <textview       android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:text="@string/hello"     android:textcolor="@color/all_black"      android:gravity="center_horizontal"/> <button android:text="@string/changecolor"  android:id="@+id/changecolor"   android:layout_width="wrap_content"   android:layout_height="wrap_content"  android:gravity="center_horizontal|center_horizontal|center"  android:layout_gravity="center_horizontal|center_horizontal|center">  </button> </linearlayout> 

strings.xml

<?xml version="1.0" encoding="utf-8"?> <resources>     <string name="hello">tjs flashlight</string>     <string name="app_name">flashcalc</string>     <string name="changecolor">i love buttons</string>     <color name="all_white">#ffffff</color>     <color name="all_black">#000000</color> </resources> 

you need view of linearlayout , set it's background color.

first need assign linearlayout id in xml. in button's onclicklistener, this.

linearlayout ll = (linearlayout) findviewbyid(r.id.layoutid); ll.setbackgroundcolor(); //i think it's called 

i forget goes in setbackgroundcolor function, you'll have up.

you should go through hello android tutorials before trying stuff on own this. haven't tried before coming help.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -