├── .gitignore ├── HeaderLayoutLibrary ├── .gitignore ├── build.gradle ├── gradle.properties ├── maven-release-aar.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── vendor │ │ └── widget │ │ └── headerlayout │ │ └── HeaderLayout.java │ └── res │ └── values │ └── attr_header_layout.xml ├── HeaderLayoutSample.iml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── vendor │ │ └── sample │ │ └── MainActivity.java │ └── res │ ├── drawable-xxhdpi │ ├── add_ic.png │ ├── edit_ic.png │ └── ic_back.png │ ├── drawable │ ├── ic_launcher_background.xml │ └── title_bg.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradlew ├── gradlew.bat ├── img.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | /build/ 3 | /.gradle/ 4 | /gradle/ 5 | /.idea/ 6 | *.iml 7 | *.properties 8 | -------------------------------------------------------------------------------- /HeaderLayoutLibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /headerlayout_aar_git/ 3 | *.iml 4 | -------------------------------------------------------------------------------- /HeaderLayoutLibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 27 5 | 6 | defaultConfig { 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 3 10 | versionName "1.1.1" 11 | 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | 26 | implementation 'com.android.support:appcompat-v7:27.1.1' 27 | } 28 | 29 | //maven打包 30 | apply from: 'maven-release-aar.gradle' 31 | -------------------------------------------------------------------------------- /HeaderLayoutLibrary/gradle.properties: -------------------------------------------------------------------------------- 1 | aar.deployPath=headerlayout_aar_git -------------------------------------------------------------------------------- /HeaderLayoutLibrary/maven-release-aar.gradle: -------------------------------------------------------------------------------- 1 | // 1.maven-插件 2 | apply plugin: 'maven' 3 | // 2.maven-信息 4 | ext {// ext is a gradle closure allowing the declaration of global properties 5 | PUBLISH_GROUP_ID = 'com.vendor.widget' 6 | PUBLISH_ARTIFACT_ID = 'headerlayout' 7 | PUBLISH_VERSION = android.defaultConfig.versionName 8 | } 9 | // 3.maven-路径 10 | uploadArchives { 11 | repositories.mavenDeployer { 12 | def deployPath = file(getProperty('aar.deployPath')) 13 | repository(url: "file://${deployPath.absolutePath}") 14 | pom.project { 15 | groupId project.PUBLISH_GROUP_ID 16 | artifactId project.PUBLISH_ARTIFACT_ID 17 | version project.PUBLISH_VERSION 18 | } 19 | } 20 | } 21 | 22 | //aar包内包含注释 23 | task androidSourcesJar(type: Jar) { 24 | classifier = 'sources' 25 | from android.sourceSets.main.java.sourceFiles 26 | } 27 | 28 | artifacts { 29 | archives androidSourcesJar 30 | } -------------------------------------------------------------------------------- /HeaderLayoutLibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /HeaderLayoutLibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /HeaderLayoutLibrary/src/main/java/com/vendor/widget/headerlayout/HeaderLayout.java: -------------------------------------------------------------------------------- 1 | package com.vendor.widget.headerlayout; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.res.ColorStateList; 7 | import android.content.res.TypedArray; 8 | import android.graphics.Rect; 9 | import android.graphics.drawable.Drawable; 10 | import android.os.Build; 11 | import android.support.annotation.RequiresApi; 12 | import android.text.TextUtils; 13 | import android.util.AttributeSet; 14 | import android.util.TypedValue; 15 | import android.view.Gravity; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | import android.widget.ImageView; 19 | import android.widget.LinearLayout; 20 | import android.widget.RelativeLayout; 21 | import android.widget.TextView; 22 | 23 | /** 24 | * 实现头部布局 25 | * Created by ljfan on 2016-11-15. 26 | */ 27 | public class HeaderLayout extends RelativeLayout { 28 | 29 | private static final ImageView.ScaleType[] sScaleTypeArray = { 30 | ImageView.ScaleType.MATRIX, 31 | ImageView.ScaleType.FIT_XY, 32 | ImageView.ScaleType.FIT_CENTER, 33 | ImageView.ScaleType.FIT_CENTER, 34 | ImageView.ScaleType.FIT_END, 35 | ImageView.ScaleType.CENTER, 36 | ImageView.ScaleType.CENTER_CROP, 37 | ImageView.ScaleType.CENTER_INSIDE 38 | }; 39 | 40 | private enum MenuAlign { 41 | 42 | /** 文字在最右边 */ 43 | ALIGN_TEXT(0), 44 | 45 | /** 图标在最右边 */ 46 | ALIGN_ICON(1), 47 | 48 | /** 文字、按钮交替 */ 49 | ALTERNATE(2), 50 | 51 | /** 文字、按钮交替 */ 52 | ALTERNATE2(3); 53 | 54 | int type; 55 | 56 | MenuAlign(int type) { 57 | this.type = type; 58 | } 59 | 60 | public static MenuAlign getType(int type) { 61 | for (MenuAlign align : values()) { 62 | if (type == align.type) { 63 | return align; 64 | } 65 | } 66 | 67 | return ALIGN_TEXT; 68 | } 69 | } 70 | 71 | private boolean isSupportTranslucentStatus; //是否支持状态栏沉浸 72 | 73 | private int mSpitLineColor; 74 | private float mSpitLineHeight; 75 | 76 | private ImageView mIvStatusPadding; 77 | private TextView mTvTitle; 78 | 79 | private int mHedaderLayoutHeight = 0; 80 | 81 | private ColorStateList mTitleTextColor; 82 | private float mTitleTextSize; 83 | private boolean mTitleAlignLeft; 84 | 85 | private View mNavigationView; 86 | private float mNavigationWidth; 87 | private float mNavigationMinWidth; 88 | private float mNavigationMaxWidth; 89 | private float mNavigationHeight; 90 | private float mNavigationMinHeight; 91 | private float mNavigationMaxHeight; 92 | 93 | private LinearLayout mLlMenu; //用于存储右边按钮 94 | private ColorStateList mItemTextColor; 95 | private float mItemTextSize; 96 | private float mItemTextPaddingLeftAndRight; 97 | 98 | public HeaderLayout(Context context) { 99 | this(context, null); 100 | } 101 | 102 | public HeaderLayout(Context context, AttributeSet attrs) { 103 | this(context, attrs, 0); 104 | } 105 | 106 | public HeaderLayout(Context context, AttributeSet attrs, int defStyleAttr) { 107 | super(context, attrs, defStyleAttr); 108 | init(context, attrs); 109 | } 110 | 111 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 112 | public HeaderLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 113 | super(context, attrs, defStyleAttr, defStyleRes); 114 | init(context, attrs); 115 | } 116 | 117 | private void init(Context context, AttributeSet attrs) { 118 | String titleText = ""; 119 | Drawable titleDrawableStart = null; 120 | Drawable titleDrawableTop = null; 121 | Drawable titleDrawableEnd = null; 122 | Drawable titleDrawableBottom = null; 123 | float titleDrawablePadding = 0; 124 | 125 | int navigationIcon = 0; 126 | String navigationText = ""; 127 | int navigationScaleType = -1; 128 | 129 | int menuIcon = 0, menu2Icon = 0; //右边的按钮 130 | int menuIconId = 0, menu2IconId = 0; //右边的按钮id 131 | String menuText = "", menu2Text = ""; //右边的文字按钮 132 | int menuTextId = 0, menu2TextId = 0; //右边的文字按钮 133 | int menuAlignType = -1; 134 | 135 | if (attrs != null) { 136 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HeaderLayout); 137 | 138 | isSupportTranslucentStatus = a.getBoolean(R.styleable.HeaderLayout_hlSupportTranslucentStatus, false); 139 | 140 | //标题相关配置 141 | titleText = a.getString(R.styleable.HeaderLayout_hlTitleText); 142 | mTitleTextColor = a.getColorStateList(R.styleable.HeaderLayout_hlTitleTextColor); 143 | if(mTitleTextColor == null) { 144 | mTitleTextColor = getResources().getColorStateList(R.color.default_header_layout_title_textColor); 145 | } 146 | mTitleTextSize = a.getDimension(R.styleable.HeaderLayout_hlTitleTextSize, getResources().getDimension(R.dimen.default_header_layout_title_textSize)); 147 | mTitleAlignLeft = a.getBoolean(R.styleable.HeaderLayout_hlTitleAlignLeft, false); 148 | 149 | int titleDrawableStartRes = a.getResourceId(R.styleable.HeaderLayout_hlTitleTextDrawableStart, 0); 150 | int titleDrawableTopRes = a.getResourceId(R.styleable.HeaderLayout_hlTitleTextDrawableTop, 0); 151 | int titleDrawableEndRes = a.getResourceId(R.styleable.HeaderLayout_hlTitleTextDrawableEnd, 0); 152 | int titleDrawableBottomRes = a.getResourceId(R.styleable.HeaderLayout_hlTitleTextDrawableBottom, 0); 153 | titleDrawablePadding = a.getDimension(R.styleable.HeaderLayout_hlTitleTextDrawablePadding, 0); 154 | if(titleDrawableStartRes != 0) { 155 | titleDrawableStart = getResources().getDrawable(titleDrawableStartRes); 156 | } 157 | if(titleDrawableTopRes != 0) { 158 | titleDrawableTop = getResources().getDrawable(titleDrawableTopRes); 159 | } 160 | if(titleDrawableEndRes != 0) { 161 | titleDrawableEnd = getResources().getDrawable(titleDrawableEndRes); 162 | } 163 | if(titleDrawableBottomRes != 0) { 164 | titleDrawableBottom = getResources().getDrawable(titleDrawableBottomRes); 165 | } 166 | 167 | menu2TextId = a.getResourceId(R.styleable.HeaderLayout_hlMenu2TextId, +0xa25); 168 | 169 | //文字按钮相关配置 170 | mItemTextColor = a.getColorStateList(R.styleable.HeaderLayout_hlItemTextColor); 171 | if(mItemTextColor == null) { 172 | mItemTextColor = getResources().getColorStateList(R.color.default_header_layout_title_textColor); 173 | } 174 | mItemTextSize = a.getDimension(R.styleable.HeaderLayout_hlItemTextSize, getResources().getDimension(R.dimen.default_header_layout_menu_textSize)); 175 | mItemTextPaddingLeftAndRight = a.getDimension(R.styleable.HeaderLayout_hlItemTextPaddingStartAndEnd, getResources().getDimension(R.dimen.default_header_layout_menu_textSize) / 2); //大概半个字的间距 176 | 177 | navigationIcon = a.getResourceId(R.styleable.HeaderLayout_hlNavigationIcon, 0); 178 | navigationText = a.getString(R.styleable.HeaderLayout_hlNavigationText); 179 | mNavigationWidth = a.getDimension(R.styleable.HeaderLayout_hlNavigationWidth, 0); 180 | mNavigationMinWidth = a.getDimension(R.styleable.HeaderLayout_hlNavigationMinWidth, 0); 181 | mNavigationMaxWidth = a.getDimension(R.styleable.HeaderLayout_hlNavigationMaxWidth, 0); 182 | mNavigationHeight = a.getDimension(R.styleable.HeaderLayout_hlNavigationHeight, 0); 183 | mNavigationMinHeight = a.getDimension(R.styleable.HeaderLayout_hlNavigationMinHeight, 0); 184 | mNavigationMaxHeight = a.getDimension(R.styleable.HeaderLayout_hlNavigationMaxHeight, 0); 185 | navigationScaleType = a.getInt(R.styleable.HeaderLayout_hlNavigationScaleType, -1); 186 | 187 | menuIcon = a.getResourceId(R.styleable.HeaderLayout_hlMenuIcon, 0); 188 | menuIconId = a.getResourceId(R.styleable.HeaderLayout_hlMenuIconId, +0xa22); 189 | menu2Icon = a.getResourceId(R.styleable.HeaderLayout_hlMenu2Icon, 0); 190 | menu2IconId = a.getResourceId(R.styleable.HeaderLayout_hlMenu2IconId, +0xa23); 191 | menuText = a.getString(R.styleable.HeaderLayout_hlMenuText); 192 | menuTextId = a.getResourceId(R.styleable.HeaderLayout_hlMenuTextId, +0xa24); 193 | menu2Text = a.getString(R.styleable.HeaderLayout_hlMenu2Text); 194 | menuAlignType = a.getInt(R.styleable.HeaderLayout_hlMenuAlign, -1); 195 | 196 | mSpitLineColor = a.getResourceId(R.styleable.HeaderLayout_hlSpitLineColor, 0); 197 | mSpitLineHeight = a.getDimension(R.styleable.HeaderLayout_hlSpitLineHeight, 2); 198 | 199 | a.recycle(); 200 | } 201 | 202 | LayoutParams params; 203 | 204 | //头部间距 用于状态栏沉浸时候使用 205 | mIvStatusPadding = new ImageView(context); 206 | mIvStatusPadding.setId(R.id.hl_iv_status_padding); 207 | addView(mIvStatusPadding); 208 | 209 | //左边按钮 210 | if(navigationIcon != 0) { 211 | mNavigationView = new ImageView(getContext()); 212 | addView(mNavigationView); 213 | mNavigationView.setId(R.id.hl_view_navigation); 214 | addButtonConfig((ImageView) mNavigationView, navigationIcon, navigationScaleType); 215 | } else if(!TextUtils.isEmpty(navigationText)){ 216 | mNavigationView = new TextView(getContext()); 217 | addView(mNavigationView); 218 | mNavigationView.setId(R.id.hl_view_navigation); 219 | addButtonConfig((TextView) mNavigationView, navigationText, mItemTextSize, mItemTextColor, (int) mItemTextPaddingLeftAndRight); 220 | } 221 | if(mNavigationView != null) { 222 | mNavigationView.setOnClickListener(new OnClickListener() { //处理返回键点击事件 223 | @Override 224 | public void onClick(View view) { 225 | ((Activity) getContext()).finish(); 226 | } 227 | }); 228 | } 229 | 230 | if (menuIcon != 0 || !TextUtils.isEmpty(menuText)) { //说明有右边按钮 231 | mLlMenu = new LinearLayout(getContext()); 232 | mLlMenu.setOrientation(LinearLayout.HORIZONTAL); 233 | addView(mLlMenu); 234 | 235 | params = (LayoutParams) mLlMenu.getLayoutParams(); 236 | params.width = LayoutParams.WRAP_CONTENT; 237 | params.height = LayoutParams.MATCH_PARENT; 238 | params.addRule(RelativeLayout.BELOW, mIvStatusPadding.getId()); 239 | params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 240 | mLlMenu.setLayoutParams(params); 241 | 242 | switch (MenuAlign.getType(menuAlignType)) { 243 | case ALIGN_TEXT: 244 | createMenuIconButton(menu2Icon, menu2IconId, navigationScaleType); 245 | createMenuIconButton(menuIcon, menuIconId, navigationScaleType); 246 | createMenuTextButton(menu2Text, menu2TextId); 247 | createMenuTextButton(menuText, menuTextId); 248 | break; 249 | case ALIGN_ICON: 250 | createMenuTextButton(menu2Text, menu2TextId); 251 | createMenuTextButton(menuText, menuTextId); 252 | createMenuIconButton(menu2Icon, menu2IconId, navigationScaleType); 253 | createMenuIconButton(menuIcon, menuIconId, navigationScaleType); 254 | break; 255 | case ALTERNATE: 256 | createMenuIconButton(menu2Icon, menu2IconId, navigationScaleType); 257 | createMenuTextButton(menu2Text, menu2TextId); 258 | createMenuIconButton(menuIcon, menuIconId, navigationScaleType); 259 | createMenuTextButton(menuText, menuTextId); 260 | break; 261 | case ALTERNATE2: 262 | createMenuTextButton(menu2Text, menu2TextId); 263 | createMenuIconButton(menu2Icon, menu2IconId, navigationScaleType); 264 | createMenuTextButton(menuText, menuTextId); 265 | createMenuIconButton(menuIcon, menuIconId, navigationScaleType); 266 | break; 267 | } 268 | } 269 | 270 | //标题栏 271 | mTvTitle = new TextView(getContext()); 272 | mTvTitle.setMaxLines(1); 273 | 274 | // 设置drawable相关 275 | if (titleDrawableStart != null || titleDrawableTop != null || titleDrawableEnd != null || titleDrawableBottom != null) { 276 | mTvTitle.setCompoundDrawablesWithIntrinsicBounds( 277 | titleDrawableStart, 278 | titleDrawableTop, 279 | titleDrawableEnd, 280 | titleDrawableBottom 281 | ); 282 | } 283 | mTvTitle.setCompoundDrawablePadding((int) titleDrawablePadding); 284 | 285 | addView(mTvTitle); 286 | mTvTitle.setGravity(Gravity.CENTER); //实现文字居中效果 在setSupportTranslucentStatus中设置高度和HeaderLayout一样就好了 287 | params = (LayoutParams) mTvTitle.getLayoutParams(); 288 | // params.addRule(RelativeLayout.BELOW, mIvStatusPadding.getId()); //本来需要这样处理,可是实际效果发现应该注释 289 | params.width = LayoutParams.WRAP_CONTENT; 290 | params.height = LayoutParams.MATCH_PARENT; 291 | 292 | if (!mTitleAlignLeft) { 293 | params.addRule(RelativeLayout.CENTER_HORIZONTAL); 294 | } else { 295 | if(mNavigationView != null) { 296 | params.addRule(RelativeLayout.RIGHT_OF, mNavigationView.getId()); //基于左边按钮的显示 297 | } else { 298 | params.leftMargin = (int)(mTitleTextSize / 2); //基于左边的显示 299 | params.addRule(RelativeLayout.ALIGN_RIGHT); 300 | } 301 | } 302 | mTvTitle.setLayoutParams(params); 303 | 304 | mTvTitle.setText(titleText); 305 | mTvTitle.setTextColor(mTitleTextColor); 306 | mTvTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleTextSize); 307 | 308 | //底部的分割线 309 | if (mSpitLineColor != 0) { 310 | ImageView ivSplitLine = new ImageView(getContext()); 311 | addView(ivSplitLine); 312 | params = (LayoutParams) ivSplitLine.getLayoutParams(); 313 | params.width = LayoutParams.MATCH_PARENT; 314 | params.height = (int) mSpitLineHeight; 315 | params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 316 | ivSplitLine.setLayoutParams(params); 317 | 318 | ivSplitLine.setImageResource(mSpitLineColor); 319 | } 320 | } 321 | 322 | private void createMenuTextButton(String menuText, int menuTextId) { 323 | if (!TextUtils.isEmpty(menuText)) { //添加第1个文字按钮 324 | TextView tv = new TextView(getContext()); 325 | if (menuTextId != 0) { 326 | tv.setId(menuTextId); 327 | } 328 | mLlMenu.addView(tv); 329 | addButtonConfig(tv, menuText, mItemTextSize, mItemTextColor, (int) mItemTextPaddingLeftAndRight); 330 | } 331 | } 332 | 333 | private void createMenuIconButton(int menuIcon, int menuIconId, int navigationScaleType) { 334 | if (menuIcon != 0) { //添加第1个图标按钮 335 | ImageView iv = new ImageView(getContext()); 336 | if (menuIconId != 0) { 337 | iv.setId(menuIconId); 338 | } 339 | mLlMenu.addView(iv); 340 | addButtonConfig(iv, menuIcon, navigationScaleType); 341 | } 342 | } 343 | 344 | private void addButtonConfig(ImageView view, int navigationIcon, int navigationScaleType) { 345 | ViewGroup.LayoutParams params = view.getLayoutParams(); 346 | if (params == null) { 347 | return; 348 | } 349 | 350 | if (params instanceof LayoutParams) { //createMenuIconButton传入的是LinearLayout.LayoutParams 351 | ((LayoutParams) params).addRule(RelativeLayout.BELOW, mIvStatusPadding.getId()); 352 | } 353 | if (mNavigationWidth > 0) { //设置宽高属性 354 | params.width = (int) mNavigationWidth; 355 | } else { 356 | params.width = LayoutParams.WRAP_CONTENT; 357 | 358 | //设置Min Max宽属性 359 | if (mNavigationMinWidth > 0) { 360 | view.setMinimumWidth((int) mNavigationMinWidth); 361 | } 362 | if (mNavigationMaxWidth > 0) { 363 | view.setMaxWidth((int) mNavigationMaxWidth); 364 | } 365 | } 366 | if (mNavigationHeight > 0) { 367 | params.height = (int) mNavigationHeight; 368 | } else { 369 | params.height = LayoutParams.MATCH_PARENT; 370 | 371 | //设置Min Max高属性 372 | if (mNavigationMinHeight > 0) { 373 | view.setMinimumHeight((int) mNavigationMinHeight); 374 | } 375 | if (mNavigationMaxHeight > 0) { 376 | view.setMaxHeight((int) mNavigationMaxHeight); 377 | } 378 | } 379 | view.setLayoutParams(params); 380 | 381 | if (navigationIcon != 0) { //设置icon 382 | view.setImageResource(navigationIcon); 383 | } 384 | if (navigationScaleType >= 0) { //设置样式 385 | view.setScaleType(sScaleTypeArray[navigationScaleType]); 386 | } 387 | 388 | } 389 | 390 | private void addButtonConfig(TextView view, String text, float textSize, ColorStateList textColor, int padding) { 391 | ViewGroup.LayoutParams params = view.getLayoutParams(); 392 | 393 | if (params instanceof LayoutParams) { 394 | ((LayoutParams) params).addRule(RelativeLayout.BELOW, mIvStatusPadding.getId()); 395 | } 396 | if (mNavigationWidth > 0) { //设置宽高属性 397 | params.width = (int) mNavigationWidth; 398 | } else { 399 | params.width = LayoutParams.WRAP_CONTENT; 400 | 401 | //设置Min Max宽属性 402 | if (mNavigationMinWidth > 0) { 403 | view.setMinimumWidth((int) mNavigationMinWidth); 404 | } 405 | if (mNavigationMaxWidth > 0) { 406 | view.setMaxWidth((int) mNavigationMaxWidth); 407 | } 408 | } 409 | if (mNavigationHeight > 0) { 410 | params.height = (int) mNavigationHeight; 411 | } else { 412 | params.height = LayoutParams.MATCH_PARENT; 413 | 414 | //设置Min Max高属性 415 | if (mNavigationMinHeight > 0) { 416 | view.setMinimumHeight((int) mNavigationMinHeight); 417 | } 418 | if (mNavigationMaxHeight > 0) { 419 | view.setMaxHeight((int) mNavigationMaxHeight); 420 | } 421 | } 422 | view.setLayoutParams(params); 423 | 424 | view.setText(text); 425 | view.setTextColor(textColor); 426 | view.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); 427 | view.setPadding(padding, 0, padding, 0); 428 | view.setGravity(Gravity.CENTER); 429 | 430 | } 431 | 432 | /** 433 | * 获取标题View控件 434 | * @return title 标题 435 | */ 436 | public TextView getTitleView() { 437 | return mTvTitle; 438 | } 439 | 440 | /** 441 | * 获取标题 442 | * @param title 标题 443 | */ 444 | public void setTitleText(String title) { 445 | if(mTvTitle != null){ 446 | mTvTitle.setText(title); 447 | } 448 | } 449 | 450 | /** 451 | * 获取导航栏左边按钮 452 | * @return title 标题 453 | */ 454 | public View getNavigationView() { 455 | return mNavigationView; 456 | } 457 | 458 | /*** 459 | * 左边按钮点击事件 460 | * @param l 点击监听 461 | */ 462 | public void setOnNavigationClickListener(OnClickListener l) { //处理返回键点击事件 463 | if(mNavigationView != null) { 464 | mNavigationView.setOnClickListener(l); 465 | } 466 | } 467 | 468 | /*** 469 | * 右边按钮点击事件 470 | * @param l 点击监听 471 | */ 472 | public void setMenuClickListener(OnClickListener l) { //处理返回键点击事件 473 | if(mNavigationView != null) { 474 | mNavigationView.setOnClickListener(l); 475 | } 476 | } 477 | 478 | @Override 479 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 480 | if (mHedaderLayoutHeight == 0) { 481 | mHedaderLayoutHeight = getLayoutParams().height; 482 | } 483 | 484 | seTranslucentStatus(isSupportTranslucentStatus); 485 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 486 | } 487 | 488 | private void seTranslucentStatus(boolean isSupport) { 489 | int top = 0; 490 | if (getContext() instanceof Activity) { 491 | top = isSupport ? getStatusHeight((Activity) getContext()) : 0; 492 | } 493 | 494 | getLayoutParams().height = mHedaderLayoutHeight + top; 495 | setLayoutParams(getLayoutParams()); 496 | 497 | mTvTitle.setPadding(0, top + 1, 0, 0); 498 | 499 | LayoutParams params = (LayoutParams) mIvStatusPadding.getLayoutParams(); 500 | params.width = LayoutParams.MATCH_PARENT; 501 | params.height = top; 502 | mIvStatusPadding.setLayoutParams(params); 503 | } 504 | 505 | /** 506 | * 状态栏高度算法 507 | * @param activity act 508 | * @return status bar height 509 | */ 510 | @SuppressLint("PrivateApi") 511 | public static int getStatusHeight(Activity activity) { 512 | Rect localRect = new Rect(); 513 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect); 514 | int statusHeight = localRect.top; 515 | if (0 == statusHeight) { 516 | Class localClass; 517 | try { 518 | localClass = Class.forName("com.android.internal.R$dimen"); 519 | Object localObject = localClass.newInstance(); 520 | int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString()); 521 | statusHeight = activity.getResources().getDimensionPixelSize(i5); 522 | } catch (Exception e) { 523 | e.printStackTrace(); 524 | } 525 | } 526 | return statusHeight; 527 | } 528 | } -------------------------------------------------------------------------------- /HeaderLayoutLibrary/src/main/res/values/attr_header_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #fff 7 | 20sp 8 | 15sp 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /HeaderLayoutSample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HeaderLayout 2 | 欢迎大家使用。
3 | 此自定义控件为头部标题栏控件

4 | 5 | 集成方法: 6 | 7 | allprojects { repositories { maven { url "https://raw.githubusercontent.com/extfff/repos/master" } } } 8 | 9 | dependencies { compile 'com.vendor.widget:headerlayout:1.1.1' } 10 | 11 | 主要提供内容: 12 | 13 | 左边按钮: 14 | 默认支持icon和文字两种方式(只能选一个,左边按钮默认只有一个) 15 | 16 | 标题文字: 17 | 支持居左和居中显示(1.1支持drawStart等操作) 18 | 19 | 右边按钮: 20 | 最多支持四个显示(2个文字、2个按钮 ) 21 | 22 | 自定义效果: 23 | 控件基于RelativeLayout,所以可以自由添加需要的内容 24 | ![截了个图](./img.png) 25 | 26 | 调用步骤:

27 | **1、可配置的所有内容** 28 | 29 | 30 | 31 | 32 | #fff 33 | 20sp 34 | 15sp 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | **2、布局引用** 87 | 88 | 110 | 111 | 有问题联系:QQ群 254202293 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.DS_Store 3 | *.iml 4 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | 6 | defaultConfig { 7 | applicationId "com.vendor.sample" 8 | minSdkVersion 15 9 | targetSdkVersion 26 10 | versionCode 2 11 | versionName "1.1" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:27.1.1' 24 | implementation project(':HeaderLayoutLibrary') 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Developer/AndroidSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/vendor/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.vendor.sample; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | public class MainActivity extends AppCompatActivity { 8 | 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.activity_main); 13 | 14 | findViewById(R.id.btn_edit).setOnClickListener(new View.OnClickListener() { 15 | @Override 16 | public void onClick(View view) { 17 | //... 18 | } 19 | }); 20 | 21 | findViewById(R.id.btn_add).setOnClickListener(new View.OnClickListener() { 22 | @Override 23 | public void onClick(View view) { 24 | //... 25 | } 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/add_ic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/drawable-xxhdpi/add_ic.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/edit_ic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/drawable-xxhdpi/edit_ic.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/drawable-xxhdpi/ic_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 17 | 22 | 27 | 32 | 37 | 42 | 47 | 52 | 57 | 62 | 67 | 72 | 77 | 82 | 87 | 92 | 97 | 102 | 107 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/title_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 24 | 25 | 39 | 40 | 57 | 58 | 75 | 76 | 93 | 94 | 113 | 114 | 134 | 135 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | 8 | #f6f6f6 9 | #000000 10 | #ffffff 11 | #99ffffff 12 | #28a7e1 13 | #4087cb 14 | #eaeaea 15 | #eeeeee 16 | #9f9f9f 17 | #808080 18 | #eb3b3b 19 | #32b16c 20 | #FFEEEEEE 21 | #FFFF01 22 | #0078FF 23 | #F07879 24 | #FF6700 25 | #FFCF2E 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | HeaderLayout 3 | Cancel 4 | Edit 5 | Add 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.3' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extfff/HeaderLayout/729fd6717789893ae74574695b4f6878b8c13634/img.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':HeaderLayoutLibrary' 2 | --------------------------------------------------------------------------------