• <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热热久久这里只有精品68| 久久久精品国产亚洲成人满18免费网站 | 蜜桃麻豆www久久国产精品| 久久天天躁狠狠躁夜夜2020老熟妇 | 亚洲AV无一区二区三区久久| 久久亚洲精精品中文字幕| 国产精品内射久久久久欢欢| 久久久噜噜噜久久中文字幕色伊伊| 亚洲精品乱码久久久久久| 嫩草影院久久99| 日本WV一本一道久久香蕉| 国产精品久久久久影院色 | 久久综合香蕉国产蜜臀AV| 一本大道久久a久久精品综合| 久久夜色精品国产噜噜亚洲a| 久久线看观看精品香蕉国产| 亚洲伊人久久精品影院| 久久久久久国产a免费观看不卡| 久久综合给合久久狠狠狠97色69| 久久久91人妻无码精品蜜桃HD| jizzjizz国产精品久久| 久久99久国产麻精品66| 激情综合色综合久久综合| 国产精品久久久福利| 国产A三级久久精品| 久久综合狠狠综合久久97色| 久久精品免费观看| 国产精品美女久久久久网| 伊人久久久AV老熟妇色| 国内精品久久久久影院亚洲| 久久久久亚洲AV无码专区网站| 99久久精品国产一区二区三区 | 亚洲伊人久久精品影院| 久久青青色综合| 久久久久亚洲国产| 免费无码国产欧美久久18| 久久99精品国产麻豆宅宅| 久久久久久免费视频| 伊人久久大香线蕉综合Av| 亚洲精品白浆高清久久久久久| 亚洲AV日韩精品久久久久久 |