浏览代码

Initial commit for UIToggleButton project.

Cristian Tanas 11 年之前
父节点
当前提交
bf008bdd9f

+ 27 - 0
UIToggleButton/AndroidManifest.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.uab.android.ui.uitogglebutton"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>

二进制
UIToggleButton/ic_launcher-web.png


二进制
UIToggleButton/res/drawable-hdpi/ic_launcher.png


二进制
UIToggleButton/res/drawable-mdpi/ic_launcher.png


二进制
UIToggleButton/res/drawable-xhdpi/ic_launcher.png


二进制
UIToggleButton/res/drawable-xxhdpi/ic_launcher.png


+ 18 - 0
UIToggleButton/res/layout/activity_main.xml

@@ -0,0 +1,18 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/relativeLayout"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${relativePackage}.${activityClass}" >
+
+    <ToggleButton
+        android:id="@+id/toggleButton1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:textOff="@string/pressme"
+        android:textOn="@string/pressme_again" />
+
+</RelativeLayout>

+ 11 - 0
UIToggleButton/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
UIToggleButton/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 9 - 0
UIToggleButton/res/values/strings.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">UIToggleButton</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="pressme">Press me</string>
+    <string name="pressme_again">Press me again</string>
+
+</resources>

+ 20 - 0
UIToggleButton/res/values/styles.xml

@@ -0,0 +1,20 @@
+<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.Light">
+        <!--
+            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>

+ 39 - 0
UIToggleButton/src/org/uab/android/ui/uitogglebutton/MainActivity.java

@@ -0,0 +1,39 @@
+package org.uab.android.ui.uitogglebutton;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.RelativeLayout;
+import android.widget.ToggleButton;
+
+public class MainActivity extends Activity {
+	
+	RelativeLayout	background;
+	ToggleButton	toggleButton;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_main);
+		
+		// Get a reference to the UI elements
+		background = (RelativeLayout) findViewById(R.id.relativeLayout);
+		toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
+		
+		// Set an OnClickListener on the toggle button
+		toggleButton.setOnClickListener(new OnClickListener() {
+			
+			@Override
+			public void onClick(View v) {
+				
+				// Toggle the background color between light and dark
+				if ( toggleButton.isChecked() )
+					background.setBackgroundColor(0xFF000000);
+				
+				else
+					background.setBackgroundColor(0xFFF3F3F3);
+			}
+		});
+	}
+}