android 自定义标题栏和自定义下拉选项PopupWindow

今天将酝酿已久的一个Android课程设计写上CSDN记录下来,可能过程一些错误的地方都忘记了,真不应该那么迟才写上来。因为近端时间都在学习数学所有把精力都没有集中在Android。

我先把我做得效果给甩上图来。

这里写图片描述

是一个可以发布文字和图文、视频的一个小功能的App,中间是ListView,然后适配器adapter。


第一个要说的是 自定义标题栏

这里写图片描述

在MainActivity.java中写到

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//自定义标题栏
    setContentView(R.layout.activity_main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mycustomtitle);//使用布局文件来定义标题栏

新建了个xml文件:mycustomtitle.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:layout_gravity="fill_horizontal"
    android:orientation="horizontal"
    android:gravity="center"
    android:background="#FFF">



    <TextView android:id="@+id/header_text"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_toLeftOf="@+id/header_right_btn"
        android:text="Mind"
        android:layout_marginLeft="5dp"
        android:textSize="20sp"
        android:gravity="center"
        android:paddingLeft="40dp"
        android:textStyle="bold"
        android:textColor="#21cbc1"
        android:singleLine="true" />

    <RelativeLayout
        android:id="@+id/rl_topbar"
        android:layout_width="1dp"
        android:layout_height="1dp"
        android:gravity="center_vertical" >

    </RelativeLayout>

    <ImageButton
        android:id="@+id/addbtn"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/add" />



</LinearLayout>

RelativeLayout在里面只是起到定位的功能,在以上没有什么作用。

这是style文件的内容

    <style name="WindowTitleBackground" >
        <item name="android:background">#FFF</item>
    </style>
    <style name="MyTheme" parent="android:Theme">
        <item name="android:windowTitleSize">60dp</item>
        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
    </style>

这是AndroidManifest.xml的要修改和填写的内容

    <activity
            android:name=".MainActivity"
            android:label="Mind"
            android:screenOrientation="portrait"
            android:theme="@style/MyTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

android:theme=”@style/MyTheme” 主要是这句 应用主题。

接下来是第二个内容:
这里写图片描述

这是点击按钮,显示的View. 这个是在网上学习的,至于原文章我也忘记了。后来我有修改过啦,他原本只是实现了功能,美化方面就没有注意了。

代码在过两天再写吧。眼睛都不舒服了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章