我先把我做得效果给甩上图来。
是一个可以发布文字和图文、视频的一个小功能的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. 这个是在网上学习的,至于原文章我也忘记了。后来我有修改过啦,他原本只是实现了功能,美化方面就没有注意了。
代码在过两天再写吧。眼睛都不舒服了。