android本地化语言与theme的实现(一)

           今天拿到了百度的一个demo,能接触到了一些大公司的代码风格,很不错,这里我会用三篇文章一一分析它的源码。

    这篇文章分析代码中的标题特点,我会列出每一步:

1.1 添加标题                                                                           

    在drawable中创建title_background.xml文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle">
    
  <gradient
        android:angle="90"
        android:endColor="#FFFFFF"
        android:startColor="#C4C4C4" />
</shape>

1.2 创建自己的style                                                                          

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="mywindowTitleBackground">
		<item name="android:background">@drawable/title_background</item>
	</style>
</resources>
上面是代码写在style.xml中,作为公用的标题格式。下面为自己的第一个界面设计标题,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="themeTitle" parent="android:Theme">
		<item name="android:windowTitleSize">46dip</item>
		<item name="android:windowTitleBackgroundStyle">@+style/mywindowTitleBackground</item>
		<item name="android:windowBackground">@color/gray</item>
		<item name="android:textColor">@color/black</item>
		<item name="android:textSize">18dip</item>
	</style>
	
	
</resources>

1.3 应用自己的style                                                                          

在manifest.xml文件中为自己的主activity加入style
<activity
            android:name="com.phoneapidemo.MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:theme="@style/themeTitle" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
完毕,以后可以一直用这种style了,自己不用每次都去设计,加快应用的设计速度。







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值