xml:

<jp.co.view.TitleLayout
android:id="@+id/titleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
TitleLayout:
package jp.co.view

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import jp.co.hyakujushibank.securestarter.R class TitleLayout(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
private var barImg: ImageView? = null
private var titleTv: TextView? = null
private var closeTv: TextView? = null init {
LayoutInflater.from(context).inflate(R.layout.layout_title, this)
val activity = (getContext() as Activity)
val backImg = findViewById(R.id.backImg) as ImageView
val closeTv = findViewById(R.id.closeTv) as TextView
val titleTv = findViewById(R.id.titleTv) as TextView
val barImg = findViewById(R.id.barImg) as ImageView
this.barImg = barImg
this.titleTv = titleTv
this.closeTv = closeTv
backImg.setOnClickListener { activity.finish() }
} fun setBarImageResource(resource: Int) {
barImg!!.setImageResource(resource)
} fun setTitle(title: String) {
titleTv!!.text = title
} fun setCloseInvisible(){
closeTv!!.visibility=View.INVISIBLE
}
}
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="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <ImageView
android:id="@+id/backImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:src="@mipmap/back_black_btn" /> <jp.co.hyakujushibank.view.JapanTextBoldView
android:id="@+id/titleTv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="はじめに"
android:textSize="16dp" /> <jp.co.hyakujushibank.view.JapanTextBoldView
android:id="@+id/closeTv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:gravity="center"
android:text="中断する"
android:textSize="16dp" />
</LinearLayout> <View
android:id="@+id/lineView"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_EBEBEB" /> <ImageView
android:id="@+id/barImg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="@mipmap/nav_tab1" />
</LinearLayout>
 
 

自定义Title的更多相关文章

  1. Android 自定义title 之Action Bar

    Android 自定义title 之Action Bar 2014-06-29  飞鹰飞龙...  摘自 博客园  阅 10519  转 25 转藏到我的图书馆   微信分享:   Action Ba ...

  2. ecshop 全站自定义title标题

    对于SEO来说,能让标题自定义的将会大大增加SEO效果,提高独立商城的流量,今天小编就收集从网上弄来ecshop全站自定义代码,很全哦! 1.Ecshop商品分类页如何实现自定义Title 最近发现很 ...

  3. Android 自定义title样式

    requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性.参数是Window类中定义的常量.一.枚举常量1.DEFAULT_FEATURES:系统默认状态,一般不需 ...

  4. ECSHOP商城全站自定义TITLE标题设置

    对于SEO来说,能让标题自定义的将会大大增加SEO效果,提高独立商城的流量,今天小编就收集从网上弄来ecshop全站自定义代码,很全哦! 1.Ecshop商品分类页如何实现自定义Title 最近发现很 ...

  5. 转 Android 4.0后,自定义Title报错 You cannot combine custom titles with other title feature

      自定义Titlebar时为了避免冲突 需要修改:AndroidManifest.xml android:theme="@style/mystyle" styles.xml文件中 ...

  6. android 自定义title

    package com.xiangyu.su; import android.app.Activity; import android.os.Bundle; import android.view.V ...

  7. android 自定义title 报错 You cannot combine custom titles with other title feat

    solution: http://www.apkbus.com/android-80416-1-1.html http://www.eoeandroid.com/forum.php?mod=viewt ...

  8. 原生HTML5 input type=file按钮UI自定义

    原生<input type="file" name="file" />长得太丑 提升一下颜值 实现方案一.设置input[type=file]透明度 ...

  9. viewPager 的可滑动 Title

    有三种方式: 1. 系统提供的title 缺点:标题在viewpager的滑动过程中也会滑动 实现:在ViewPager布局中添加 PagerTabStrip 或者是 PagerTitleStrip ...

随机推荐

  1. JQ中的问题

    $(function(){$(document).bind("click", function (e) {$(e.target).closest("p").cs ...

  2. github小技巧之Creating a pull request 创建 pull 请求

    创建一个 pull 请求是为了协作更改存储库.这些变化会产生一个分支,它确保主分支保持干净整洁. 与commits提交是不同的,提交是fork之后的一种操作. 在你可以打开一个 pull 请求之前,您 ...

  3. ASP.NET MVC执行流程图

  4. hihoCoder #1068 : RMQ-ST算法(模板)

    AC G++ 826ms 146MB 思路: 时间复杂度O(nlogn). //#include <bits/stdc++.h> #include <iostream> #in ...

  5. 验证 .NET 4.6 的 SIMD 硬件加速支持的重要性

    SIMD 的意思是 Single Instruction Multiple Data.顾名思义,一个指令可以处理多个数据. .NET Framework 4.6 推出的 Nuget 程序包 Syste ...

  6. Example of how to implement a view-based source list (NSOutlineView) using Cocoa Bindings

    You tagged this with the cocoa-bindings tag, so I assume you mean "with bindings." I whipp ...

  7. 转 在Qt中用QAxObject来操作Excel

    最近写程序中需要将数据输出保存到Excel文件中.翻看<C++ GUI Programming with Qt 4>(Second Edition)发现可以在Qt中运用ActiveX控件, ...

  8. python基础一 day13 迭代器

    # 双下方法# print([1].__add__([2]))# print([1]+[2]) # 迭代器# l = [1,2,3]# 索引# 循环 for# for i in l:# i## for ...

  9. 公共Service的抽取小例

    package cn.sxx.service; import java.util.List; public interface BaseService<T,Q> { public void ...

  10. shell脚本,awk替换{}里面的内容

    如何将oxo{axbxc}oxo{dxexf}oxo里面的{}里面的x 替换为; 用awk实现 [root@localhost 09-30]# echo 'oxo{axbxc}oxo{dxexf}ox ...