当前位置:首页 > 智能硬件 > 人工智能AI
[导读]android改变全局字体大小 随着app越来越人性化,这就造成了需求的越加变态,这里,我想向所有移动开发的同仁说,干死需求他丫的,好了,废话说到这里,下面进入正题,如何全局改变字体大小,首先AcT

android改变全局字体大小
随着app越来越人性化,这就造成了需求的越加变态,这里,我想向所有移动开发的同仁说,干死需求他丫的,好了,废话说到这里,下面进入正题,如何全局改变字体大小,首先AcTIvity继承BaseacTIvity:
[java] view plain copy
public class MainAcTIvity extends BaseAcTIvity {  
  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);   
    }  
}  
 
然后在BaseActivity里做了这么一件事,
[java] view plain copy
public class BaseActivity extends Activity {  

    private int states = 3;  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
  
  
        super.onCreate(savedInstanceState);  
  
  
        if (1 == states) {  
            setTheme(R.style.Default_TextSize_Small);  
  
  
        } else if (2 == states) {  
  
  
            setTheme(R.style.Default_TextSize_Middle);  
        } else {  
            setTheme(R.style.Default_TextSize_Big);  
        }  
    }  
}  
 
一般情况下 我们调节全局字体大小会在app的设置菜单里,这里我们模拟大,中,小 三种字体分别为 1,2,3,很明显我们是以setTheme的方式来掌控全局字体大小,这时候 重点来了,如何set过主题,字体大小就会发生改变呢,我们来看xml布局文件,
[java] view plain copy
<LinearLayout 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:orientation="vertical" >  

    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="@string/hello_world"  
        android:textSize="?textsize" />  

    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="@string/hello_world"  
        android:textSize="?textsize2" />  

    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="@string/hello_world"  
        android:textSize="?textsize3" />  

</LinearLayout>  
 
本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭