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

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产黑森林| 丰满少妇人妻久久久久久4| 欧美激情精品久久久久久久| 奇米影视7777久久精品人人爽| 蜜桃麻豆WWW久久囤产精品| 无码人妻久久一区二区三区免费| 久久国产乱子精品免费女| 久久男人AV资源网站| 狠狠色婷婷综合天天久久丁香| 一本久久免费视频| 国产农村妇女毛片精品久久| 亚洲av日韩精品久久久久久a| 久久国产福利免费| 日韩av无码久久精品免费| 久久久久国产亚洲AV麻豆| 精品久久久久香蕉网| 国产成人无码精品久久久性色| 国产精品久久久久AV福利动漫| 亚洲国产精品成人AV无码久久综合影院| 久久久精品人妻一区二区三区四| 亚洲欧美一级久久精品| 97久久国产亚洲精品超碰热| 亚洲人AV永久一区二区三区久久 | 伊人久久大香线蕉av不变影院| 精品久久久久久久中文字幕| www性久久久com| 久久A级毛片免费观看| 久久久女人与动物群交毛片| 国产偷久久久精品专区| 欧美国产成人久久精品| 久久夜色精品国产噜噜亚洲a| 久久亚洲色一区二区三区| 国内精品久久久久影院网站| 伊人久久大香线蕉精品| 亚洲国产精品久久久久久| 999久久久国产精品| 久久99精品久久久久久水蜜桃| 久久av免费天堂小草播放| 久久99热这里只有精品国产| 久久精品国产亚洲精品| 色综合久久久久综合99|