没有合适的资源?快使用搜索试试~ 我知道了~
首页Android Studio 创建自定义控件的方法
我们知道,当系统控件并不能满足我们的需求时,我们就需要来创建自定义控件,主要有两种方法 (1)引入布局 下面来自定义一个控件,iPhone的标题栏,创建一个标题栏并不是什么难事,加入两个button一个TextView就行了,可是在我们的应用中,有很多页面都是需要这样的标题栏,我们不可能每个活动都写一遍布局,这个时候我们就可以用引用布局的方法,新建一个title.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
资源详情
资源评论
资源推荐

Android Studio 创建自定义控件的方法创建自定义控件的方法
我们知道,当系统控件并不能满足我们的需求时,我们就需要来创建自定义控件,主要有两种方法
((1)引入布局)引入布局
下面来自定义一个控件,iPhone的标题栏,创建一个标题栏并不是什么难事,加入两个button一个TextView就行了,可是在我
们的应用中,有很多页面都是需要这样的标题栏,我们不可能每个活动都写一遍布局,这个时候我们就可以用引用布局的方
法,新建一个title.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="wrap_content"
android:background="#817D7D"
>
<Button
android:id="@+id/title_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="back"
android:textColor="#fff"/>
<TextView
android:id="@+id/title_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:textColor="#c0c0c0"
android:textSize="24sp"
android:text="title text" />
<Button
android:id="@+id/title_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:textColor="#fff"
android:text="edit" />
</LinearLayout>
现在标题栏已经写好了,接下来就要在程序中使用,修改activity_main.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"
>
<include layout="@layout/title"/>
</LinearLayout>
我们只要通过一句include语句引进来就行了
<include layout="@layout/title"/>
最后我们需要在MainActivity中将系统自带的标题栏屏蔽
package com.example.ch03;
import android.drm.DrmStore;


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0