在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ Android樣式示例
Android 應(yīng)用組件
使用布局文件自定義Android組件
Android通知
Android主題示例
Android JetPlayer實(shí)例
Android MediaPlayer(多媒體播放)
Android AbsoluteLayout
Android FrameLayout
Android Gestures/手勢
Android AutoCompleteTextView(自動(dòng)完成)實(shí)例
Android 資源組織和訪問
Android ListView
Android GridView
Android數(shù)據(jù)備份
Android撥打電話
Android發(fā)送短信/SMS
Android ProgressDialog
SimpleCursorAdapter
Android發(fā)送電子郵件
Android Activity
Android TextView
Android事件處理
Android TableLayout
Android加載Spinner
Android內(nèi)容提供者
Android自定義字體
Android Service
Android CheckBox
Android Intent過濾器
Android LinearLayout
Android登錄實(shí)例
Android RadioButton
Android樣式和主題
Android自定義組件及屬性
Android UI控件
Android Animation(動(dòng)畫)實(shí)例
Android Camera(攝像頭)
Android ToggleButton
Android Clipboard(復(fù)制/剪貼板)
Android音頻捕獲(錄音)
發(fā)布Android應(yīng)用
Android Alertdialog(警告對話框)
Android圖片效果
Android內(nèi)部存儲
Android基于位置服務(wù)
Android RadioGroup
Android AutoCompleteTextView
Android Bluetooth(藍(lán)牙)實(shí)例
Android RelativeLayout
Android最佳實(shí)踐
Android本地化
Android自定義組件
Android教程
Android 架構(gòu)
Android UI布局
Android Button
Android Hello World示例
Android音頻管理器實(shí)例
ArrayAdapter
Android拖放
Android碎片/片段
Android圖片切換
Android JSON解析器
Android開發(fā)環(huán)境搭建
Android Spinner
Android樣式示例
使用活動(dòng)代碼自定義Android組件
Android ImageButton
Android EditText
Android廣播接收器

Android樣式示例

下面的例子演示了如何使用Style的一些元素?,F(xiàn)在開始創(chuàng)建一個(gè)簡單的Android應(yīng)用程序,按照以下步驟:

步驟 描述
1 使用Android Studio創(chuàng)建一個(gè)Android應(yīng)用程序項(xiàng)目,并將其命名為:StyleDemo
2 修改src/MainActivity.java文件,以添加click事件偵聽器和處理程序定義的兩個(gè)按鈕
3 定義全局樣式在文件 res/values/style.xml ,同時(shí)為按鈕自定義屬性
4 修改 res/layout/activity_main.xml 文件的默認(rèn)內(nèi)容包括一套Android的UI控件,并使用所自定義的風(fēng)格。
5 定義所需的常量在 res/values/strings.xml 文件
6 運(yùn)行該應(yīng)用程序啟動(dòng)Android模擬器并驗(yàn)證應(yīng)用程序所做的修改結(jié)果。

以下是主活動(dòng)Activity文件src/ com.yiibai.styledemo/MainActivity.java 文件的內(nèi)容。這個(gè)文件可以包括每個(gè)生命周期基本方法。

package com.example.styledemo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //--- find both the buttons---
        Button sButton = (Button) findViewById(R.id.button_s);
        Button lButton = (Button) findViewById(R.id.button_l);
        
        // -- register click event with first button ---
        sButton.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               // --- find the text view --
               TextView txtView = (TextView) findViewById(R.id.text_id);
               // -- change text size --
               txtView.setTextSize(20);
           }
        });
        
        // -- register click event with second button ---
        lButton.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               // --- find the text view --
               TextView txtView = (TextView) findViewById(R.id.text_id);
               // -- change text size --
               txtView.setTextSize(24);
           }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}

將下列 res/values/styles.xml 文件的內(nèi)容,另外這還有 styleCustomButtonStyle 定義:

<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>
    
   <!-- Custom Style defined for the buttons. -->
   <style name="CustomButtonStyle">
      <item name="android:layout_width">100dp</item>
      <item name="android:layout_height">38dp</item>
      <item name="android:capitalize">characters</item>
      <item name="android:typeface">monospace</item>
      <item name上一篇:Android廣播接收器下一篇:Android JetPlayer實(shí)例