WindowFeature(窗口样式)笔记

关于窗口样式的几个小例子
1 在窗体上显示图标和提示文字(即窗口的自定义标题)
//MainActivity如下
package cn.ifeng.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class WindowFeatureTestActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//相当于告诉系统:我将自定义窗口标题布局       
        setContentView(R.layout.main);       
        this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//添加窗口标题布局
    }
}
//title.xml如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageView 
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
    />
    <TextView 
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:text="正在运行,请稍等"
    />

</LinearLayout>

2 为窗口添加进度条,可用于提示用户程序在运行
//MainActivity如下
//注意在布局文件中: style="@android:style/Widget.ProgressBar.Inverse"
//表示使用系统自带的进度条样式
this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//相当于告诉系统:我要使用带进度条的窗口布局       
setContentView(R.layout.main);       
this.getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progressbar);//添加窗口进度条布局
setProgressBarIndeterminateVisibility(true);

//progressbar.xml如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ProgressBar 
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        style="@android:style/Widget.ProgressBar.Inverse"
    />

</LinearLayout>

3 为窗口的左上角添加一个图标
//MainActivity如下
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);
this.getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);

4 窗口全屏显示
//MainActivity如下
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);    
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谷哥的小弟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值