界面上有几种控件:一些Button ,一些TextView , 还有些TexEdit,它们的字体太小,一个一个设置太麻烦,有没有简单的代码可统一次设定? 写个样式 放在style.xml里面,字体大小和颜色 都是放在values目录下面配置成常量。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的界面使用的样式中加入一个全局字体样式。 这样所有未设置字体大小的,全部会使用这个字体大小了<style name="AppTheme" parent="AppBaseTheme"> <item name="android:textSize">28sp</item></style> 兄弟,这个全局设置我试了下好像不行,我一般都是在每个控件中设置一个style属性。<style name="TextStyle"> <item name="android:textSize">30sp</item> </style>用的时候 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="北京天安门" style="@style/TextStyle"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TextStyle" /> 兄弟,这个全局设置我试了下好像不行,我一般都是在每个控件中设置一个style属性。<style name="TextStyle"> <item name="android:textSize">30sp</item> </style>用的时候 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="北京天安门" style="@style/TextStyle"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TextStyle" /> 兄弟,这个全局设置我试了下好像不行,我一般都是在每个控件中设置一个style属性。<style name="TextStyle"> <item name="android:textSize">30sp</item> </style>用的时候 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="北京天安门" style="@style/TextStyle"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TextStyle" /> 你要在配置文件里使用这个主题才有效果<application android:name=".app.MyApp" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".ui.activity.LoginActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 你看我的配置文件,已用了一个主题,怎么能让这两个主题都同时使用呢,帮帮吧修改下代码 <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <activity android:name=".MyActivity" android:label="@string/app_name" android:icon="@drawable/icon" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 我的做法是在项目中为每种控件设置一个style,然后应用到该类型的控件上,这样就可以保持样式的统一,也好修改,某些控件需要特殊设置的话也可以直接设置对应的属性即可,很方便 项目目录知道的吧,styles文件在哪应该是知道的吧。AndroidManifest.xml知道吧 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="场(厂)内专用机动车辆定期监督检验" android:theme="@style/AppTheme"> AndroidManifest.xml知道吧 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="场(厂)内专用机动车辆定期监督检验" android:theme="@style/AppTheme">兄弟,你看你都回答了两次了,再加点力,这100分肯定是你的了,问题是你看,我的AndroidManifest.xml里已用了 一种主题android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen",请问怎么能同时用两种主题 android:theme="@style/AppTheme" style已经算是最有效的了,你可以把一些设置相同的属性写入,然后你只需在每个控件中引用style就行了 给你个范例<TextView style="@style/right_triangle" android:layout_centerVertical="true" android:layout_marginRight="14dip" /><EditText style="@style/right_triangle" android:layout_centerVertical="true" android:layout_marginRight="14dip" /><style name="wrap"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style><style name="right" parent="wrap"> <item name="android:layout_marginRight">10dip</item> <item name="android:layout_centerVertical">true</item> <item name="android:layout_alignParentRight">true</item> </style><style name="right_triangle" parent="right"> <item name="android:textsize">16sp</item> </style>这样textview和edittext的textsize,layout_marginRight,layout_centerVertical,layout_alignParentRight,layout_width,layout_height就都设置好了,如果你在<EditText style="@style/right_triangle" android:layout_centerVertical="true" android:layout_marginRight="14dip" />这里有设置了以上属性,类似重写,子类的起作用,style里的对应属性就不起作用了 <style name="wrap"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style><style name="right" parent="wrap"> <item name="android:layout_marginRight">10dip</item> <item name="android:layout_centerVertical">true</item> <item name="android:layout_alignParentRight">true</item> </style><style name="right_triangle" parent="right"> <item name="android:textsize">16sp</item> </style>这些放在values目录下的styles.xml中 android获取包含图片的文件夹 android布局文件中,EditText 默认情况下,键盘会弹出的问题,在线等 这样的菜单效果怎么实现? strings.xml的探讨 adt安装 subMenu标题背景颜色设置? webview 调用js 内存被自动释放了 看大家android界面设计是拿Android Design UI Kit设计的,不直接在eclipse里设计,但是UI KIT怎么用呢 Genymotion最新的2.9不能免费下载了吗 在圖片上拖移標籤 的demo 或者做法? android app混淆错误
<item name="android:textSize">28sp</item>
</style>
<style name="TextStyle">
<item name="android:textSize">30sp</item>
</style>
用的时候
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="北京天安门"
style="@style/TextStyle"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextStyle" />
<style name="TextStyle">
<item name="android:textSize">30sp</item>
</style>
用的时候
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="北京天安门"
style="@style/TextStyle"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextStyle" />
<style name="TextStyle">
<item name="android:textSize">30sp</item>
</style>
用的时候
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="北京天安门"
style="@style/TextStyle"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextStyle" />
android:name=".app.MyApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ui.activity.LoginActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
你看我的配置文件,已用了一个主题,怎么能让这两个主题都同时使用呢,帮帮吧修改下代码
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<activity android:name=".MyActivity" android:label="@string/app_name"
android:icon="@drawable/icon" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
AndroidManifest.xml知道吧 <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="场(厂)内专用机动车辆定期监督检验"
android:theme="@style/AppTheme">
AndroidManifest.xml知道吧 <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="场(厂)内专用机动车辆定期监督检验"
android:theme="@style/AppTheme">
兄弟,你看你都回答了两次了,再加点力,这100分肯定是你的了,
问题是你看,我的AndroidManifest.xml里已用了 一种主题android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
,请问怎么能同时用两种主题
android:theme="@style/AppTheme"
style="@style/right_triangle"
android:layout_centerVertical="true"
android:layout_marginRight="14dip" />
<EditText
style="@style/right_triangle"
android:layout_centerVertical="true"
android:layout_marginRight="14dip" />
<style name="wrap">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="right" parent="wrap">
<item name="android:layout_marginRight">10dip</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:layout_alignParentRight">true</item>
</style>
<style name="right_triangle" parent="right">
<item name="android:textsize">16sp</item>
</style>这样textview和edittext的textsize,layout_marginRight,layout_centerVertical,layout_alignParentRight,layout_width,layout_height就都设置好了,如果你在<EditText
style="@style/right_triangle"
android:layout_centerVertical="true"
android:layout_marginRight="14dip" />这里有设置了以上属性,类似重写,子类的起作用,style里的对应属性就不起作用了
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="right" parent="wrap">
<item name="android:layout_marginRight">10dip</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:layout_alignParentRight">true</item>
</style>
<style name="right_triangle" parent="right">
<item name="android:textsize">16sp</item>
</style>
这些放在values目录下的styles.xml中