Android Studio: Cara Membuat Android Apps 9

From OnnoWiki
Jump to navigation Jump to search

In this part of my Android tutorial I will focus on Android Styles and Themes. A style specifies a collection of properties that specify how a widget looks. A theme is a series of styles that are applied to an Activity.

We’ll make different styles for different versions of Android. We’ll create styles to apply to single and multiple widgets. We’ll cover inheriting styles, default themes, applying themes and much more.

If you like videos like this it helps if you share it on Google Plus with a click here

Here is the URL I mentioned in the video Android R.stylable

Cheat Sheets From the Video

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"

   package="com.newthinktank.derekbanas.androidthemes" >


   <application
       android:allowBackup="true"
       android:icon="@drawable/ic_launcher"
       android:label="@string/app_name"
       android:theme="@style/AppTheme" >
       <activity
           android:name=".MyActivity"
           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>

values/styles.xml

<resources>


   <style name="AppBaseTheme" parent="android:Theme.Light">
   </style>
   <style name="AppTheme" parent="AppBaseTheme">


   </style>

</resources>

values-v11/styles.xml

<resources>

   <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
   </style>

</resources>

values-v14/styles.xml

<resources>


   <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">


       <item name="android:editTextColor">#ffb62a23</item>
       <item name="android:textColorPrimary">#ffb62a23</item>
       <item name="android:textColorSecondary">#ffb62a23</item>
       <item name="android:textColorTertiary">#ffb62a23</item>
       <item name="android:textColorPrimaryInverse">#ffb62a23</item>
       <item name="android:textColorSecondaryInverse">#ffb62a23</item>
       <item name="android:textColorTertiaryInverse">#ffb62a23</item>
       <item name="android:windowBackground">#ffedeba6</item>
       <item name="android:fontFamily">sans-serif</item>
       <item name="android:textStyle">bold</item>


   </style>
   <style name="TextView1">
       <item name="android:textSize">30sp</item>
       <item name="android:textStyle">bold</item>
   </style>
   <style name="EditText" parent="@style/TextView1">
       <item name="android:textStyle">normal</item>
   </style>
   <style name="TextView1.TextView2">
       <item name="android:padding">30dp</item>
   </style>
   <style name="TextView1.TextView2.TextView3">
       <item name="android:layout_marginTop">15dp</item>
   </style>



</resources>

activity_my.xml

<RelativeLayout 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"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin"
   tools:context=".MyActivity">
   <TextView
       android:text="@string/hello_world"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       style="@style/TextView1"
       android:id="@+id/textView1" />
   <EditText
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/editText"
       android:text="Enter Here"
       style="@style/EditText"
       android:layout_below="@+id/textView3"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true" />
   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="New Text"
       android:id="@+id/textView2"
       android:layout_below="@+id/editText"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true"
       style="@style/TextView1.TextView2" />
   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="New Text"
       android:id="@+id/textView3"
       android:layout_below="@+id/textView4"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true"
       style="@style/TextView1.TextView2.TextView3" />
   <Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="New Button"
       android:id="@+id/button"
       android:layout_below="@+id/textView5"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true" />

</RelativeLayout>

- See more at: http://www.newthinktank.com/2014/07/make-android-apps-9/#sthash.rIHfyDXM.dpuf


Referensi