• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Codejie's C++ Space

            Using C++

            Android DEV : Amazing Theme and Style


                工作上需要動態(tài)改變app字體大小,而我的LAC也可能需要這個,于是半公半私地看起來...google了很多頁面,越發(fā)覺得Theme和Style神奇了...

                咱也講不好,還是直接放上幾段代碼做記錄吧...

                styles.xml

            <resources>
                <style name="small_title_text">
                  <item name="android:textSize">22sp</item>
                  <item name="android:textColor">@color/color1</item>
                  <item name="android:textStyle">normal</item>
                  <item name="android:paddingBottom">5dip</item>
               </style>
               <style name="small_body_text">
                  <item name="android:textSize">16sp</item>
                  <item name="android:textColor">@color/color1</item>
                  <item name="android:textStyle">normal</item>
                  <item name="android:paddingBottom">5dip</item>
               </style>
               <style name="large_title_text">
                  <item name="android:textSize">40sp</item>
                  <item name="android:textColor">@color/color</item>
                  <item name="android:textStyle">normal</item>
                  <item name="android:paddingBottom">5dip</item>
               </style>

               <style name="large_body_text">
                  <item name="android:textSize">20sp</item>
                  <item name="android:textColor">@color/color</item>
                  <item name="android:textStyle">normal</item>
                  <item name="android:paddingBottom">5dip</item>
               </style>

              <!-- Base application theme is the default theme. -->
              <style name="Theme" parent="android:Theme">
              </style>

              <style name="Theme.Small" parent="Theme">
                 <item name="textTitle">@style/small_title_text</item>
                 <item name="textBody">@style/small_body_text</item>
              </style>

              <style name="Theme.Large"  parent="Theme">
                  <item name="textTitle">@style/large_title_text</item>
                  <item name="textBody">@style/large_body_text</item>
              </style>
                
            </resources>

                attrs.xml
            <?xml version="1.0" encoding="utf-8"?>
            <resources>
                   <attr name="textTitle" format="reference" />
                   <attr name="textBody" format="reference" />    
            </resources>

                main.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:paddingBottom
            ="@dimen/activity_vertical_margin"
                android:paddingLeft
            ="@dimen/activity_horizontal_margin"
                android:paddingRight
            ="@dimen/activity_horizontal_margin"
                android:paddingTop
            ="@dimen/activity_vertical_margin"
                tools:context
            =".MainActivity" >

                <TextView
                    
            android:id="@+id/textView1"
                    style
            ="?textTitle"
                    android:layout_width
            ="wrap_content"
                    android:layout_height
            ="wrap_content"
                    android:layout_alignParentLeft
            ="true"
                    android:layout_alignParentTop
            ="true"
                    android:text
            ="@string/hello_world" />

                <Button
                    
            android:id="@+id/button1"
                    style
            ="?textBody"
                    android:layout_width
            ="match_parent"
                    android:layout_height
            ="wrap_content"
                    android:layout_alignLeft
            ="@+id/textView1"
                    android:layout_below
            ="@+id/textView1"
                    android:layout_marginTop
            ="14dp"
                    android:text
            ="ToggleButton" />

            </RelativeLayout>

                main.java
                protected void onButtonClick() {
                    
                    if (toggle) {
                        this.setTheme(R.style.Theme_Large);
                        setContentView(R.layout.activity_main);
                    } else {
                        this.setTheme(R.style.Theme_Small);
                        setContentView(R.layout.activity_main);            
                    }
                    Button btn = (Button) this.findViewById(R.id.button1);
                    btn.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            onButtonClick();
                        }
                        
                    });
                    
                    toggle = !toggle;
                }


            file://C:\Program Files\sdk\platforms\android-17\data\res
            http://developer.android.com/guide/topics/ui/themes.html
            http://stackoverflow.com/questions/3241729/android-dynamically-change-style-at-runtime

            posted on 2013-05-10 14:37 codejie 閱讀(418) 評論(2)  編輯 收藏 引用 所屬分類: 隨筆而已G7

            評論

            # re: Android DEV : Amazing Theme and Style 2013-05-14 19:15 jan

            看著好親切啊,咱這些天,就是被這些東西.欺負(fù)的  回復(fù)  更多評論   

            # re: Android DEV : Amazing Theme and Style[未登錄] 2013-05-14 23:13 codejie

            @jan
            我敢說這幾天欺負(fù)你的一定不是它們...表打錯了哦...它們兄弟們間只是長的差不多而已了,就跟包子和饅頭一樣...  回復(fù)  更多評論   

            公告

            Using C++

            導(dǎo)航

            統(tǒng)計

            留言簿(73)

            隨筆分類(513)

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久国产精品偷99| 国产69精品久久久久777| 亚洲欧美另类日本久久国产真实乱对白| 国产精品日韩欧美久久综合| 久久这里只有精品视频99| 精品一二三区久久aaa片| 国产美女久久精品香蕉69| 丁香五月综合久久激情| 武侠古典久久婷婷狼人伊人| 婷婷综合久久中文字幕蜜桃三电影 | 亚洲精品久久久www| 久久精品国产AV一区二区三区| 久久99热只有频精品8| 久久婷婷五月综合成人D啪| 久久精品人成免费| 伊人久久大香线蕉AV色婷婷色| 国产69精品久久久久777| 国产成人精品综合久久久久| 精品国产乱码久久久久久浪潮| 亚洲AV乱码久久精品蜜桃| 久久免费大片| 四虎国产永久免费久久| 亚洲第一极品精品无码久久| 久久久精品日本一区二区三区| 久久久久成人精品无码中文字幕| 亚洲国产精品成人久久蜜臀 | 久久久久无码精品| 国产精品久久国产精麻豆99网站 | 久久久久国产精品嫩草影院 | 久久久久久国产精品无码下载| 国产精品免费久久| 99久久精品国内| 国产69精品久久久久777| 久久人人爽人人爽人人AV东京热| 亚洲国产精品无码久久九九 | 久久精品视屏| 欧美粉嫩小泬久久久久久久 | 久久婷婷人人澡人人| 久久夜色精品国产| 久久久久久免费视频| 久久天天日天天操综合伊人av|