• <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ù)  更多評論   

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

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

            公告

            Using C++

            導(dǎo)航

            統(tǒng)計

            留言簿(73)

            隨筆分類(513)

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            伊人久久大香线蕉综合Av| 国产精品一区二区久久精品无码| 2021国内精品久久久久久影院| 久久综合鬼色88久久精品综合自在自线噜噜 | 色88久久久久高潮综合影院| 久久免费的精品国产V∧ | 亚洲精品午夜国产va久久| 成人午夜精品无码区久久 | 日韩电影久久久被窝网| 久久久亚洲欧洲日产国码aⅴ| 精品久久久久久久中文字幕| 一本一本久久aa综合精品| 国产高潮久久免费观看| 亚洲中文字幕无码久久2020| 久久婷婷色综合一区二区| 久久ww精品w免费人成| 久久久久久国产a免费观看黄色大片 | 久久99精品久久久久久hb无码| 国产精品日韩深夜福利久久| 亚洲精品乱码久久久久久蜜桃图片 | 久久久久综合中文字幕| 69久久夜色精品国产69| 精品人妻伦九区久久AAA片69 | 精品多毛少妇人妻AV免费久久| 久久精品视频免费| 色偷偷久久一区二区三区| 无码8090精品久久一区| 精品国产婷婷久久久| 91精品免费久久久久久久久| 久久久久99精品成人片直播| 久久亚洲日韩看片无码| 亚洲精品视频久久久| 久久99精品久久久久久野外| 久久精品国产一区| 久久综合中文字幕| 久久精品中文字幕久久| 国内精品久久久久影院一蜜桃| 久久精品国产99国产精品导航| 久久久久久国产精品无码下载| 久久热这里只有精品在线观看| 久久精品国产99久久久古代 |