Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Created June 26, 2015 23:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save udacityandroid/4072f90aaec69dca18eb to your computer and use it in GitHub Desktop.
Save udacityandroid/4072f90aaec69dca18eb to your computer and use it in GitHub Desktop.
Android for Beginners : Quantity Picker Button Style Solution
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<EditText
android:id="@+id/name_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:inputType="text" />
<TextView
style="@style/HeaderTextStyle"
android:text="@string/toppings" />
<CheckBox
android:id="@+id/whipped_cream_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="24dp"
android:text="@string/whipped_cream"
android:textSize="16sp" />
<CheckBox
android:id="@+id/chocolate_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="24dp"
android:text="@string/chocolate"
android:textSize="16sp" />
<TextView
style="@style/HeaderTextStyle"
android:text="@string/quantity" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
style="@style/QuantityPickerButtonStyle"
android:onClick="decrement"
android:text="-" />
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/initial_quantity_value"
android:textColor="@android:color/black"
android:textSize="16sp" />
<Button
style="@style/QuantityPickerButtonStyle"
android:onClick="increment"
android:text="+" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="submitOrder"
android:text="@string/order" />
</LinearLayout>
</ScrollView>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<!-- Style for header text in the order form -->
<style name="HeaderTextStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">48dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textAllCaps">true</item>
</style>
<!-- Style for a button in the quantity picker -->
<style name="QuantityPickerButtonStyle">
<item name="android:layout_width">48dp</item>
<item name="android:layout_height">48dp</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment