GVKun编程网logo

angular-material – 如何将mdButton文本设置为小写?(angular doc)

11

在这篇文章中,我们将带领您了解angular-material–如何将mdButton文本设置为小写?的全貌,包括angulardoc的相关情况。同时,我们还将为您介绍有关androidMD风格组件(

在这篇文章中,我们将带领您了解angular-material – 如何将mdButton文本设置为小写?的全貌,包括angular doc的相关情况。同时,我们还将为您介绍有关android MD 风格组件 (TextInputLayout AutoCompleteTextView MaterialButton SwitchMaterial MaterialRadio)(二)、Angular - 如何验证 Angular Material stepper 中的每一步、Angular Material 2 md卡响应列、Angular Material mdInput控件周围的边框的知识,以帮助您更好地理解这个主题。

本文目录一览:

angular-material – 如何将mdButton文本设置为小写?(angular doc)

angular-material – 如何将mdButton文本设置为小写?(angular doc)

从 here可以看出,mdButton将使用大写字母设置文本.如果我想制作小写怎么办?
使用css text-transform编写自己的类,例如
.tolowercase {
    text-transform: lowercase;
}

.tocapitalize {
    text-transform: capitalize;
}

并将其应用于输入/按钮.

如果你想在整个系统中使用htis行为覆盖你的css中的.md-button类,

.md-button {    
    text-transform: capitalize !important;/*For Lower case use lowercase*/
}

android MD 风格组件 (TextInputLayout AutoCompleteTextView MaterialButton SwitchMaterial MaterialRadio)(二)

android MD 风格组件 (TextInputLayout AutoCompleteTextView MaterialButton SwitchMaterial MaterialRadio)(二)

android material design 风格组件 TextInputLayout,MaterialButton,SwitchMaterial,MaterialRadio

  • 基本使用
  • app:endIconMode 模式
  • 前置与后置
  • 其他常用操作
  • 可下拉选择的
  • TextInputLayout 配合 AutoCompleteTextView 使用
  • Ohter
  • materialRadioButton
  • MaterialCheckBox
    • 自定义按钮:
    • 自定义 background
  • SwitchMaterial

相关文章:

  • MaterialButton,MaterialButtonToggleGroup,Chip,ChipGroup (一) [material 环境配置,必看!]

今日完成效果:

效果一 效果二 效果三

基本使用

<com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:hint="请输入账号">

     <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" />
 </com.google.android.material.textfield.TextInputLayout>

app:endIconMode 模式

<com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:hint="请输入密码" app:endIconMode="password_toggle" app:startIconDrawable="@drawable/ic_emoji_02" app:startIconTint="@color/white" app:startIconTintMode="multiply" >
 <!-- app:endIconDrawable="@drawable/ic_emoji_03" app:endIconTint="@color/white" app:endIconTintMode="multiply" -->
    
     <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="numberPassword" />
 </com.google.android.material.textfield.TextInputLayout>
  • app:endIconMode end 模式
  • startIcon 图标
  • startIconTint start 色调
  • endIcon 图标
  • endIconTint end 色调

效果图:

password clear custom (自定义)
TextInputLayout#endIconMode="password_toggle"
TextInputEditText#inputType=“numberPassword”
TextInputEditText#endIconMode=“clear_text” TextInputEditText#endIconMode=“custom”

前置与后置

<com.google.android.material.textfield.TextInputLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_marginRight="5dp" android:layout_weight="1" app:prefixText="$" app:suffixText="$" app:prefixTextColor="@color/black">

     <!-- android:inputType="numberSigned" 数字 -->
     <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="numberSigned" />
 </com.google.android.material.textfield.TextInputLayout>
  • app:prefixText 前置图标
  • app:prefixTextColor 前置图标颜色
  • app:suffixText 后置图标
  • app:suffixTextColor 后置图标颜色

其他常用操作

<com.google.android.material.textfield.TextInputLayout android:id="@+id/errorTextInput" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:hint="你可以尝试输入12位" app:boxStrokeErrorColor="@color/red" app:counterEnabled="true" app:counterMaxLength="11" app:errorEnabled="true" app:helperText="你可以输入11位哦~" app:helperTextEnabled="true" app:placeholderText="更加专业的hint">

    <com.google.android.material.textfield.TextInputEditText android:id="@+id/errorEditText" android:layout_width="match_parent" android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
  • boxStrokeErrorColor 输入错误颜色 [默认红色]
  • counterEnabled 计数器是否启动
  • counterMaxLength 计数器最大值
  • errorEnabled 错误检测启动
  • placeholderText 占位符
  • helperTextEnabled 帮助文字是否启动
    动态代码:
binding.errorEditText.doOnTextChanged {
    text, start, count, after ->
            if (text?.length!! >= 11) {
   
                binding.errorTextInput.error = "动态代码设置.错误信息"
                binding.errorEditText.error = "只能输入11位"
            } else {
   
                binding.errorTextInput.error = null
            }
            binding.errorTextInput.errorIconDrawable = null
        }
  • doOnTextChanged() 监听变化

请添加图片描述

可下拉选择的

<com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:hint="可下拉的">

     <AutoCompleteTextView android:id="@+id/autoText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="none" tools:ignore="LabelFor" />
 </com.google.android.material.textfield.TextInputLayout>

动态设置数据:

val items =
            listOf(
                "Material",
                "Design",
                "Components",
                "Android",
                "kotlin",
                "java",
                "ios",
                "c",
                "c++",
                "js",
                "python"
            )
        val adapter = ArrayAdapter(this, R.layout.list_item, items)
        binding.autoText.setAdapter(adapter)

list_item.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:ellipsize="end" android:maxLines="1" android:textAppearance="?attr/textAppearanceSubtitle1" />

其他样式:

  • Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu 弹出输入框
  • Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu 不弹出输入框
  • Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu 不弹出输入框 2
弹出输入框 不弹出输入框 不弹出输入框 2

TextInputLayout 配合 AutoCompleteTextView 使用

tips: AutoCompleteTextView 继承自 EditText

<com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:hint="可下拉的">
            <!-- android:popupBackground 弹出背景【不起作用,需要动态代码!】 -->
            <AutoCompleteTextView android:id="@+id/autoText" android:layout_width="match_parent" android:layout_height="wrap_content" android:completionHint="这是一条提示语。。。" android:dropDownWidth="100dp" android:dropDownHeight="200dp" android:dropDownHorizontalOffset="50dp" android:dropDownVerticalOffset="50dp" android:dropDownSelector="@drawable/ic_emoji_09" android:inputType="text" android:popupBackground="@drawable/ic_emoji_05" tools:ignore="LabelFor" />
        </com.google.android.material.textfield.TextInputLayout>

动态代码:

val items =
            listOf(
                "Material",
                "Design",
                "Components",
                "Android",
                "kotlin",
                "java",
                "ios",
                "c",
                "c++",
                "js",
                "python"
            )
        val adapter = ArrayAdapter(this, R.layout.list_item, items)
        binding.autoText.setAdapter(adapter)

        // 设置AutoCompleteTextView.pop背景
        binding.autoText.setDropDownBackgroundResource(R.drawable.ic_emoji_06)
  • android:dropDownHeight 设置下拉高度

  • android:completionHint 提示语

  • android:dropDownWidth 弹出 pop 的宽

  • android:dropDownHeight 弹出 pop 的高

  • android:inputType 允许输入类型

  • android:dropDownHorizontalOffset 距离水平的位置

  • android:dropDownVerticalOffset 距离垂直侧的位置

  • android:dropDownSelector 选中时候的背景

效果图:


注意:这里设置背景一定要谨慎使用:

android:dropDownSelector="@drawable/ic_emoji_09" // 回收时候展示的图片

android:popupBackground="@drawable/ic_emoji_05" // 不起作用需要动态设置代码
binding.autoText.setDropDownBackgroundResource(R.drawable.ic_emoji_06) // 动态代码替换

bug 分析:
当第一次进入的时候,如果弹出的软键盘pop重叠的时候,会显示不了图片,可能显示图片了只是刷新掉了,众所周知,软键盘和弹出的 pop 都是一个 window, 我猜测可能是这里是配没有适配全,来看两张图就懂了!

bug 复现 理想状态

可以看出,只要是人写的代码,或多或少存在一定的毛病 (偷笑)

Ohter

还有一些其他主题和风格一起看看吧!

<com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" app:shapeAppearance="@style/CutTheme2" android:hint="TextInputLayout.OutlinedBox">

     <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" />
 </com.google.android.material.textfield.TextInputLayout>

@style/CutTheme2:

<style name="CutTheme2"> <item name="cornerFamily">cut</item> <item name="cornerSize">16dp</item> </style>

这个上一章说过就不重复提了

materialRadioButton

MaterialRadioButton 貌似没有什么变化,目前还没有看出来… 拿常用的方法看看就可以了!

<RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checkedButton="@id/javaRadioButton" android:orientation="horizontal">

     <!-- android:buttonTint 设置 色调颜色 tips: 单选按钮的颜色默认为 ?attr/colorOnSurface (未选中)和 ?attr/colorSecondary(选中) -->
     <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/javaRadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:buttonTint="@color/red" android:text="java" />

     <com.google.android.material.radiobutton.MaterialRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:buttonTint="@color/black" android:text="kotlin" />

     <com.google.android.material.radiobutton.MaterialRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:buttonTint="@color/teal_200" android:text="python" />

     <com.google.android.material.radiobutton.MaterialRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:button="@null" android:buttonTint="@color/teal_200" android:text="我也是单选" />
 </RadioGroup>

MaterialCheckBox

materialCheckBox 和 CheckBox 好像也是相差无几,那就介绍几种自定义的方法吧

自定义按钮:

<com.google.android.material.checkbox.MaterialCheckBox android:id="@+id/materialCheckoutBox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/check_box_material_select" android:text="自定义materialCheckBox" app:useMaterialThemeColors="false" />
  • button 设置按钮状态
  • app:useMaterialThemeColors=“false” 自定义颜色

自定义选择器:
@drawable/check_box_material_select:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:drawable="@drawable/ic_emoji_04"/>
    <item android:state_checked="false" android:drawable="@drawable/ic_emoji_03"/>
</selector>

效果图:

自定义 background

<com.google.android.material.checkbox.MaterialCheckBox android:id="@+id/materialCheckoutBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/switch_material_select" android:button="@null" android:paddingLeft="20dp" android:paddingRight="20dp" android:text="绿色未选中" android:textColor="@color/white" />
  • android:button="@null" 隐藏按钮

自定义选中效果:
@drawable/switch_material_select:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:drawable="@drawable/switch_material_open"/>
    <item android:state_checked="false" android:drawable="@drawable/switch_material_clone"/>
</selector>

打开时,switch_material_open.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="@dimen/dp_10" />
    <stroke android:width="1dp" android:color="@color/red" />
    <solid android:color="@color/black"/>
</shape>

关闭时,switch_material_clone.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="@dimen/dp_10" />
    <stroke android:width="1dp" android:color="@color/green" />
    <solid android:color="@color/black" />
</shape>

效果:

SwitchMaterial

switchMaterial 比较简单,直接看所有属性了!

<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/materialSwitch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="这是一串文字" android:textOff="" android:textOn="" app:showText="true" app:thumbTint="@color/green" app:trackTint="@color/red" app:track="@drawable/switch_material_select" app:trackTintMode="multiply" app:switchMinWidth="100dp" app:switchPadding="20dp" />
  • android:textOff [checked=false help 文字]
  • android:textOn [checked=true help 文字]
  • app:showText [显示 help 文字]
  • app:switchMinWidth [文字宽度]
  • app:switchPadding [文字和 switch 的距离]
  • app:switchTextAppearance 自定义样式
  • android:typeface 设置字体
  • app:thumbTint 按钮颜色
  • app:trackTint 轨道颜色 [可配合 app:trackTintMode]
  • app:track 自定义颜色 / 背景

来看看效果吧:


完整代码

相关文章:

  • MaterialButton,MaterialButtonToggleGroup,Chip,ChipGroup (一) [material 环境配置,必看!]

原创不易,您的点赞就是对我最大的支持!

Angular - 如何验证 Angular Material stepper 中的每一步

Angular - 如何验证 Angular Material stepper 中的每一步

如何解决Angular - 如何验证 Angular Material stepper 中的每一步?

在 Angular-12 中,我正在实施 Material Stepper。它有两 (2) 个步骤:

组件:

export class SignupCompanyComponent implements OnInit {
  isLinear = true;
  isLoading = false;
  companySetupForm!: FormGroup;
  companyForm!: FormGroup;
  idForm!: FormGroup;

  ngOnInit() {
    this.companyForm = this.fb.group({
      companyName: ['''',[Validators.required,Validators.minLength(3),Validators.maxLength(100)]]
    });
    this.idForm = this.fb.group({
      registrationNumber: ['''',Validators.maxLength(100)]],});
  }

  get fc() {
    return this.companyForm.controls;
  };
  get fi() {
    return this.idForm.controls;
  };

  onSubmit() {}
}

HTML:

<mat-horizontal-stepper [linear]="isLinear" #stepper labelPosition="bottom">
  <mat-step [stepControl]="companyForm">
    <form [formGroup]="companyForm">
      <ng-template matStepLabel matStepperIcon="phone">Company Info</ng-template>

      <div>
        <div>
          <label for="name">Company Name:<span>*</span></label>}
          <input type="text" formControlName="companyName" placeholder="Company Name"required/>
        </div>
        <div *ngIf="fc.companyName.touched && fc.companyName.invalid">
          <div *ngIf="fc.companyName.hasError(''required'')">
            <div>
              Company Name is required!
            </div>
          </div>
          <div *ngIf="fc.companyName.hasError(''minlength'')">
            <div>
              Company Name cannot be less than 3 characters!
            </div>
          </div>
          <div *ngIf="fc.companyName.hasError(''maxlength'')">
            <div>
              Company Name cannot be more than 100 characters!
            </div>
          </div>
        </div>
      </div>
      <div>
        <button mat-raised-button color="primary" matStepperNext>Next</button>
      </div>
    </form>
  </mat-step>
  <mat-step [stepControl]="idForm">
    <form [formGroup]="idForm">
      <ng-template matStepLabel>Company ID</ng-template>
      <div>
        <div>
          <label for="registration_number">Registration Number:<span>*</span></label>
          <input type="text" formControlName="registrationNumber" placeholder="Registration Number"required/>
        </div>
        <div *ngIf="fi.registrationNumber.touched && fi.registrationNumber.invalid">
          <div *ngIf="fi.registrationNumber.hasError(''required'')">
            <div>
              Company Reg. No. is required!
            </div>
          </div>
          <div *ngIf="fi.registrationNumber.hasError(''maxlength'')">
            <div>
              Company Reg. No. cannot be more than 100 characters!
            </div>
          </div>
        </div>
      </div>
      <div>
        <button mat-raised-button color="black" matStepperPrevIoUs>Back</button> &nbsp;
        <button mat-raised-button color="success" [disabled]="isLoading" type="submit" (click)="onSubmit()">
                <span *ngIf="isLoading"></span>
                  Submit
              </button> &nbsp;
        <button mat-raised-button color="warn" (click)="stepper.reset()">Reset</button>
      </div>
  </mat-step>
</mat-horizontal-stepper>

当每个 formControl 被触摸时,Material Stepper 工作正常。它立即显示错误。 但是当点击Next Button时,Step1(companyForm)中没有填写数据,虽然没有移动到下一步或表单,但没有显示错误。

我希望它验证每个步骤并在触摸每个表单控件时显示它。

我如何实现这一目标?

谢谢

解决方法

材料似乎没有将表单标记为已触摸,所以我会重新绑定按钮:

<button mat-raised-button color="primary" (click)="onFirstStepDone()">Next</button>

在组件中,您需要对步进器的引用:

@ViewChild(''stepper'') stepper: MatHorizontalStepper;

onFirstStepDone() {
   if(!this.companyForm .valid) {
       // this should make all invalid fields light up in red
       this.companyForm.markAllAsTouched();
       return;
   }
   this.stepper.next();
}
,

我做的两件事是将字段验证设置为 onBlur like;

this.companyForm = this.fb.group({
      companyName: ['''',[Validators.required,Validators.minLength(3),Validators.maxLength(100)]]
    },{ updateOn: "blur" });

...我个人不喜欢在必填字段有效之前允许继续,所以我将步进器按钮设置为禁用,直到它像;

<button mat-raised-button
        color="primary"
        matStepperNext
        [disabled]="companyForm.status != ''VALID''">
   Next
</button>

或者一定要看看下面曼哈顿先生的评论来验证最后的表格,你可以通过将上面的 { updateOn: "blur" }blur 更改为 submit 来完成同样的事情

Angular Material 2 md卡响应列

Angular Material 2 md卡响应列

我正在寻找这种布局的Angular 2/4示例.我需要从两列牌开始(左侧2个,右侧1个).但是,如果屏幕很小,它们应该折叠到一列.我可以在带有div的CSS中完成它,但在Material 2中必须有一个简单的方法 – 有很多Material 1的例子.

这段代码改编自Angular Material 1答案,但它不起作用(我将“row”更改为“column”,希望这样可行,但我只得到一列有三张牌):

how do i create a grid of cards with angular material?

<divlayout="column" layout-wrap>
    <md-card flex="40" flex-sm="80">
      <md-card-content>
        <h2>Left Card 1</h2>
      </md-card-content>
    </md-card>

    <md-card flex="40" flex-sm="80">
      <md-card-content>
        <h2>Left Card 2</h2>
      </md-card-content> 
    </md-card>
</div>

<divlayout="column" layout-wrap>
    <md-card flex="40" flex-sm="80">
      <md-card-content>
        <h2>Right Column </h2>
      </md-card-content>
    </md-card>
</div>

从答案:“在这个例子中,你将有两张牌(每张40%),当屏幕调整到-sm时,牌将达到80%.”

解决方法

首先,在您的应用中添加@ angular / flex-layout包.阅读有关 “flex-layout”的更多信息.然后,您需要在app.module.ts导入条目中导入FlexLayoutModule:

import { FlexLayoutModule } from '@angular/flex-layout';

....
@NgModule({
    imports: [
        // other modules
        // .....
        FlexLayoutModule
    ],....

然后,您可以在应用中使用“flex-layout”.要像上面提到的那样使卡片响应,您可以使用以下模板:

<div fxLayout="row" fxLayout.xs="column">
    <md-card fxFlex="40%;" fxFlex.xs="80%">
        <md-card-content>
            <h2>Left Card 1</h2>
        </md-card-content>
    </md-card>

    <md-card fxFlex="40%;" fxFlex.xs="80%">
        <md-card-content>
            <h2>Left Card 2</h2>
        </md-card-content>
    </md-card>

    <md-card fxFlex="20%;" fxFlex.xs="80%">
        <md-card-content>
            <h2>Right Column </h2>
        </md-card-content>
    </md-card>
</div>

链接到stackblitz demo.

Angular Material mdInput控件周围的边框

Angular Material mdInput控件周围的边框

我想将我的mdInput控件设置为在其周围有一个黑盒子:

<md-form-field>
      <input type="text" mdInput [(ngModel)]="row.price" placeholder="Price">
    </md-form-field>

我尝试在输入控件周围放置一个div,其中style =“border:1px solid black;”但是它只在输入控件本身周围创建边框.我试图将边框添加到md-form-field但是它只在左侧和右侧放置边框(但是如果我能够在顶部和底部获得边框,它看起来像我能够实现的任何方式来判断高度)实现那个?

解决方法

覆盖默认Material2样式的推荐方法是使用 ViewEncapsulation. deep,:: ng-deep和>>>是折旧的,将来可能会被贬值( official documentation).

The shadow-piercing descendant combinator is deprecated and support is
being removed from major browsers and tools. As such we plan to drop
support in Angular (for all 3 of /deep/,>>> and ::ng-deep).

要为输入设置边框,请在component.ts中包含以下内容:

import { ViewEncapsulation } from '@angular/core';

@Component({
    ....
    encapsulation: ViewEncapsulation.None
})

…然后在组件样式中添加以下内容:

/* To display a border for the input */
.mat-input-flex.mat-form-field-flex{
   border: 1px solid black;
}

/* To remove the default underline */
.mat-input-underline.mat-form-field-underline {
   background: transparent;
}

/* To remove the underline ripple */
.mat-input-ripple.mat-form-field-ripple{
   background-color: transparent; 
}

这是working demo.

关于angular-material – 如何将mdButton文本设置为小写?angular doc的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于android MD 风格组件 (TextInputLayout AutoCompleteTextView MaterialButton SwitchMaterial MaterialRadio)(二)、Angular - 如何验证 Angular Material stepper 中的每一步、Angular Material 2 md卡响应列、Angular Material mdInput控件周围的边框等相关内容,可以在本站寻找。

本文标签:

上一篇无法打开ServletContext资源[/WEB-INF/applicationContext.xml](servlet无法访问资源)

下一篇angular – Mat-autocomplete – 如何访问所选选项?(angular访问数据库)