我已经为Android应用程序提供了一些扩展代码。
主要活动具有一个展示有Button的FrameLayout。该按钮的背景是可绘制(XML)。
==> resources / layout / Layout.axml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999">
.../...
<Button
android:id="@+id/the_button"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="40dp"
android:gravity="center_vertical|center_horizontal"
android:background="@drawable/btn" />
</FrameLayout>
该按钮使用可绘制对象使其具有边框。
==> resources / drawable / btn.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="oval">
<solid android:color="#20000000"/>
<stroke android:width="2dp" android:color="#000000"/>
<size android:width="60dp" android:height="50dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#FF000000"/>
<stroke android:width="2dp" android:color="#000000"/>
<size android:width="60dp" android:height="50dp" />
</shape>
</item>
</selector>
在应用程序生命周期的某一时刻,按钮的边框(上面的笔触)应更改颜色。如何更改上面的笔触颜色?
使用常规的FindViewById<Button>(Resource.Id.the_button)
无济于事。
谢谢。
解决方案-Th。G.hakim
Button _theButton = FindViewById<Button>(Resource.Id.the_button);
GradientDrawable _stroke = (GradientDrawable)_theButton.Background.Current;
_stroke.SetStroke(2, Color.Red);
答案 0 :(得分:0)
我会这样做:
import {
Component,
OnInit,
Input,
Output,
EventEmitter
} from '@angular/core';
import {
MatStepper
} from '@angular/material';
import {
FormGroup,
FormBuilder
} from '@angular/forms';
@Component({
selector: 'cby-step',
templateUrl: './cby-step.component.html',
styleUrls: ['./cby-step.component.scss']
})
export class CbyStepComponent implements OnInit {
@Input() stepper: MatStepper;
public childForm: FormGroup;
constructor(private fb: FormBuilder) {}
ngOnInit() {
this.childForm = this.fb.group({
id: [0, '']
});
}
previous() {
this.updateForm();
this.stepper.previous();
}
next() {
this.updateForm();
this.stepper.next();
}
updateForm() {
this.childForm.controls['id'].setValue(this.stepper.selectedIndex);
console.log(this.childForm.controls['id'].value);
}
}