• <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


                工作上需要動態改變app字體大小,而我的LAC也可能需要這個,于是半公半私地看起來...google了很多頁面,越發覺得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 閱讀(412) 評論(2)  編輯 收藏 引用 所屬分類: 隨筆而已G7

            評論

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

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

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

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

            公告

            Using C++

            導航

            統計

            留言簿(73)

            隨筆分類(513)

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久久99精品一区二区| 久久精品99无色码中文字幕| 免费无码国产欧美久久18| 亚洲国产精品无码久久久久久曰| 久久综合狠狠综合久久97色| 精品多毛少妇人妻AV免费久久| 久久国产色av免费看| 青青青国产精品国产精品久久久久| 久久夜色精品国产亚洲| 久久经典免费视频| 婷婷综合久久中文字幕| 亚洲午夜无码久久久久| 久久免费国产精品| 国产亚洲精久久久久久无码| 免费一级做a爰片久久毛片潮| 久久综合狠狠综合久久综合88| 久久国产精品波多野结衣AV| 精品久久人妻av中文字幕| 美女久久久久久| 91精品国产91久久| 粉嫩小泬无遮挡久久久久久| 性做久久久久久久久浪潮| 99久久综合国产精品二区| 777米奇久久最新地址| 久久综合九色综合网站| 丰满少妇人妻久久久久久4| 久久久久亚洲精品无码蜜桃| 久久笫一福利免费导航| 久久最新免费视频| 久久久久婷婷| 久久国产成人| 色婷婷狠狠久久综合五月| 青草影院天堂男人久久| 国产成人久久精品激情| 99久久777色| 精品久久久久久国产91| 久久99精品综合国产首页| 久久久久四虎国产精品| 国产欧美一区二区久久| 99久久综合狠狠综合久久止| 久久这里只有精品久久|