设置窗口标题事件(onTitleChanged)

直接看源代码:

package com.luohaibo.testdemo08;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle("窗口标题");
    }
    //设置窗口标题按钮的单击事件方法
    public void onClick_SetTitle(View view){
        setTitle("新窗口标题");
        setTitleColor(12345);
    }
    //窗口完全开始后调用该方法
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        Log.d("MainActivity", "onPostCreate");
        super.onPostCreate(savedInstanceState);
    }
    @Override
    protected void onTitleChanged(CharSequence title, int color) {
        // TODO Auto-generated method stub
        super.onTitleChanged(title, color);
        Log.d("MainActivity", "onTitleChanged_title:" + title);
        Log.d("MainActivity", "onTitleChanged_color:" + color);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

布置文件如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="onClick_SetTitle"
        android:text="设置窗口标题"  />


</LinearLayout>

 没有点击Button按钮时候Log输入如下:

点击了Button按钮后Log输入如下:

posted @ 2014-04-20 13:43  我是不可不戒  阅读(1857)  评论(0编辑  收藏  举报