zoukankan      html  css  js  c++  java
  • Android 自定义标题栏 并进行事件处理

    Android自定义TitleBar 自定义标题栏 并进行事件处理
     
    安卓自带的标题栏感觉很是难看,那么我们可以自定义titlebar
    首先创建自定义标题栏xml文件 放在layout目录下
    <?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" >
     
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="blog.sina.com.cn/ruipheng"
            android:textColor="@android:color/background_dark"
            android:textSize="20dp"
             />
     
     
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册" />
     
    </LinearLayout>
     
    在代码中引入
     
     
    //自定义标题栏
    this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.test);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
    R.layout.title_bar);
    我们发现 这样的话,标题栏的高度是原生的,不能满足我们的需求,于是我们在value目录下创建styles.xml文件
    代码如下
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="custom_window_title_background">
            <item name="android:background">@drawable/skinpic_blue</item>
        </style>
        <style name="custom_title">
            <item name="android:windowTitleSize">50dp</item>
            <item name="android:windowTitleBackgroundStyle">@style/custom_window_title_background</item>
        </style>  
    </resources>
    这样自定义titlebar的工作就完成了,那么怎样处理titleBar中的事件呢!其实很简单,和处理本页面其他的控件一样的.我曾经以为处理上面的空间与自定义Dialog中xml的文件的方法一样,实际上我是错了,根本不需要那样处理
     
     
    Button btn = (Button) findViewById(R.id.button1);
    final TextView text = (TextView) findViewById(R.id.textView1);
    btn.setOnClickListener(new OnClickListener() {
     
    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    text.setText("我的新浪博客");
    //System.out.println("我的新浪博客");
     
    }
    });
     
     
    http://blog.sina.com.cn/s/blog_62d3ddc00100z5u6.html
  • 相关阅读:
    my first android test
    VVVVVVVVVV
    my first android test
    my first android test
    my first android test
    ini文件
    ZZZZ
    Standard Exception Classes in Python 1.5
    Python Module of the Week Python Module of the Week
    my first android test
  • 原文地址:https://www.cnblogs.com/jiezzy/p/2671624.html
Copyright © 2011-2022 走看看