3.14 MonoForAndroid用户人机界面--控制不同的文字字体
2014-06-24 14:07
281 查看
除了文字颜色之外,与文字对象息息相关的文字大小(Size)及字体(font)是整个TextView文字实例的最后一站.
本例通过单击按钮来改变TextVies的字体大小与字体
Main.axml
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace Ex03_14
{
[Activity(Label = "Ex03_14", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private TextView mText;
private Button sizeButton;
private Button fontButton;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
mText = (TextView)FindViewById(Resource.Id.mytextview);
sizeButton = (Button)FindViewById(Resource.Id.sizebutton);
fontButton = (Button)FindViewById(Resource.Id.fontbutton);
sizeButton.Click += delegate {
mText.SetTextSize(Android.Util.ComplexUnitType.Px, 20);
};
fontButton.Click += delegate
{
mText.SetTypeface(Android.Graphics.Typeface.DefaultBold, Android.Graphics.TypefaceStyle.Bold);
};
}
}
}
本例通过单击按钮来改变TextVies的字体大小与字体
Main.axml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mylayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/white"> <!-- 文字以mytextview為id 引用string.xml的textview_str參數 文字使用color.xml中定義的drawable顏色 --> <TextView android:id="@+id/mytextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/textview_str" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:textColor="@drawable/blue" /> <!-- 改變大小按鈕以sizebutton為id 引用sizebutton_str並置中安排於文字下方 --> <Button android:id="@+id/sizebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sizebutton_str" android:layout_below="@+id/mytextview" android:layout_centerHorizontal="true" /> <!-- 改變字型按鈕以fontbutton為id 引用fontbutton_str並與sizebutton並排 --> <Button android:id="@+id/fontbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fontbutton_str" android:layout_alignTop="@+id/sizebutton" android:layout_toLeftOf="@+id/sizebutton" /> </RelativeLayout>
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace Ex03_14
{
[Activity(Label = "Ex03_14", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private TextView mText;
private Button sizeButton;
private Button fontButton;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
mText = (TextView)FindViewById(Resource.Id.mytextview);
sizeButton = (Button)FindViewById(Resource.Id.sizebutton);
fontButton = (Button)FindViewById(Resource.Id.fontbutton);
sizeButton.Click += delegate {
mText.SetTextSize(Android.Util.ComplexUnitType.Px, 20);
};
fontButton.Click += delegate
{
mText.SetTypeface(Android.Graphics.Typeface.DefaultBold, Android.Graphics.TypefaceStyle.Bold);
};
}
}
}
相关文章推荐
- 3.10 MonoForAndroid用户人机界面--不同Activity之间的数据传递
- 3.13 MonoForAndroid用户人机界面--置换文字颜色的机关
- 3.1 MonoForAndroid用户人机界面-更改与显示文字标签-TextView标签的使用
- 3.4 MonoForAndroid用户人机界面-置换TextVew文字
- 3.5 MonoForAndroid用户人机界面-取得手机屏幕大小
- Android SDK 开发范例大全 ---3.14控制不同的文字字体
- 3.8 MonoForAndroid用户人机界面-手机页面的转换
- 3.9 MonoForAndroid用户人机界面--调用另一个Activity
- 3.16 MonoForAndroid用户人机界面--自制计算器
- 3.17 MonoForAndroid用户人机界面--关于(About)程序信息 Menu功能菜单程序设计
- 3.15 MonoForAndroid用户人机界面--如IPHONE拖动相片特效 Gallery画廊
- 3.11 MonoForAndroid用户人机界面--返回数据到前一个Activity
- 3.6 MonoForAndroid用户人机界面-样式化的定型对象
- 3.2 MonoForAndroid用户人机界面-更改手机窗口画面底色
- 【Android每日一讲】2012.10.29 控制不同的文字字体 -- Typeface对象使用
- 控制不同的文字字体(Typeface对象的使用)
- Android 一个TextView中设置文字不同字体大小和颜色的最完整方法
- 借鉴drawable文件夹,使用dimens控制字体大小、边距大小。适配Android不同机型,不同屏幕
- 控制不同文字字体Typeface
- Mono For Android 如何控制程序在自动旋转功能开启下不进行横竖屏切换