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 myButton =(Button)findViewById(R.id.button1);
myButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "AHOJ",
Toast.LENGTH_LONG).show();
}
});
// or set onClickListener
myButton.setOnClickListener(myListener);
//end onCreate .....
private OnClickListener myListener = new OnClickListener() {
public void onClick(View v) {
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
How add pair of strings to Hashtable, how get pair key value from Hashtable, how split string, basic Java Android example.
MainClass.java
MainClass.java
import java.util.Enumeration;
import java.util.Hashtable;
public class MainClass {
public static void main(String[] arg) {
// english;germany dictionary
String[] arrayOfString = { "one;eine", "two;zwei", "three;drei" };
Hashtable<String, String> hashTable = new Hashtable<String, String>();
for(String s: arrayOfString){
String[] array = s.split(";");
String sKey ="", sValue="";
if(array.length > 1){
sKey = array[0]; sValue = array[1];
hashTable.put(sKey, sValue);
}
}
Enumeration<String> enumer = hashTable.keys();
while (enumer.hasMoreElements()) {
String keyFromTable = (String) enumer.nextElement();
// get Returns the value to which the specified key is mapped,
// or null if this map contains no mapping for the key
System.out.println(keyFromTable + " = " + hashTable.get(keyFromTable));
}
}
}
/*
two = zwei
one = eine
three = drei
*/
If the app have transparent menu and you do not want this,
try delete @style/AppTheme in application tag in AndroidManifest.xml
and try run module - project. If menu is not transparent , maybe it caused
Or try set values\styles.xml into basic Theme
try delete @style/AppTheme in application tag in AndroidManifest.xml
and try run module - project. If menu is not transparent , maybe it caused
<application
android:allowBackup="true"
android:icon="@drawable/dicts_ico"
android:label="@string/app_name"
android:theme="@style/AppTheme" // delete this row - run app - try menu
>
Or try set values\styles.xml into basic Theme
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Black">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
Check
- is sett debug mode on device?
- enabled debugging over USB?
- is device right connected?
- have you downloaded and instaled drivers for your device on PC?
- For Windows //developer.android.com/sdk/win-usb.html
- try disconnect and connect USB cable
- try do restart Android Studio
Wiktionary - SDK samples Android
about.xml
protected void showAbout() {
// Inflate the about message contents
View messageView = getLayoutInflater().inflate(R.layout.about, null, false);
// When linking text, force to always use default color. This works
// around a pressed color state bug.
TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
int defaultColor = textView.getTextColors().getDefaultColor();
textView.setTextColor(defaultColor);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.app_icon);
builder.setTitle(R.string.app_name);
builder.setView(messageView);
builder.create();
builder.show();
}
about.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
//www.apache.org/licenses/LICENSE-2.0
-->
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dip">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/app_descrip"
android:textColor="?android:attr/textColorPrimaryInverse" />
<TextView
android:id="@+id/about_credits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dip"
android:textSize="16sp"
android:text="@string/app_credits"
android:autoLink="web"
android:textColor="?android:attr/textColorPrimaryInverse" />
</LinearLayout>
GregorianCalendar cal = new GregorianCalendar(); Boolean b = cal.isLeapYear(2012); // true, Android example.
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
StringBuilder strBuild = new StringBuilder();
GregorianCalendar cal = new GregorianCalendar();
Boolean b = cal.isLeapYear(2012); // true
strBuild.append("Is leap year 2012? " + b + "
");
b = cal.isLeapYear(2014); // false
strBuild.append("Is leap year 2014? " + b + "
");
txtV.setText(strBuild);
}
}
Editace: 2011-09-28 07:45:52
Počet článků v kategorii: 396
Url:button-android