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

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

是一个可以发布文字和图文、视频的一个小功能的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);//使用布局文件来定义标题栏
  • 1

新建了个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>
  • 1

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>
  • 1

这是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>
  • 1

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

接下来是第二个内容:

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

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

apple_51426592

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

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

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

打赏作者

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

抵扣说明:

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

余额充值