我刚drawable在res文件夹下添加了一个新文件夹.在drawable文件夹中,我ic_launcher.png从drawable-hdpi文件夹中复制了该文件.ImageButton当我按下按钮时,我想通过新的标准图像更改标准图像.我写了一些代码,但是当我启动应用程序时,它崩溃了.
Button imgButton;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.imgButton).setOnClickListener(imgButtonHandler);
}
View.OnClickListener imgButtonHandler = new View.OnClickListener() {
public void onClick(View v) {
imgButton.setBackgroundResource(R.drawable.ic_launcher);
}
};
Run Code Online (Sandbox Code Playgroud)
编辑:我改为这个,这也行不通.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgButton = (Button) findViewById(R.id.imgButton);
imgButton.setOnClickListener(imgButtonHandler);
}
View.OnClickListener imgButtonHandler = new View.OnClickListener() {
public void onClick(View v) {
imgButton.setBackgroundResource(R.drawable.ic_launcher);
}
};
Run Code Online (Sandbox Code Playgroud)
编辑2:这个工作.谢谢大家.
ImageButton button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= (ImageButton)findViewById(R.id.imgButton); …Run Code Online (Sandbox Code Playgroud) 我在 Firebase Cloud Function 中尝试了以下操作来执行 Axios 请求,但没有奏效。
const functions = require('firebase-functions');
const axios = require('axios');
const cors = require('cors')({ origin: true });
exports.checkIP = functions.https.onRequest((req, res) => {
cors(req, res, () => {
if( req.method !== "GET" ) {
return res.status(401).json({
message: "Not allowed"
});
}
return axios.get('https://api.ipify.org?format=json')
.then(data => {
console.log(data)
res.status(200).json({
message: data.ip
})
})
.catch(err => {
res.status(500).json({
error: err
})
})
})
})
Run Code Online (Sandbox Code Playgroud)
我还搜索了很多关于如何将 Axios 与 Cloud Functions 结合使用的示例,但没有找到。上面的代码没有返回任何东西。
任何人都可以帮忙吗?
PS:我已经在我的 Firebase 帐户中添加了帐单明细,并且没有使用免费的 Spark 计划,而是使用了 …
我想知道是否有办法检测小部件中发生的溢出并返回一个布尔值以根据trueorfalse值进行一些更改。
例如,我有一个里面有文字的容器。我想检测文本何时溢出容器,之后我将在某些条件下使容器变大。我知道有一些方法,auto_size_text但这里的重点是检测溢出。
我有这样的数据:
scores: {
uid1: {
score: 15,
displayName: "Uciska"
},
uid2: {
score: 3,
displayName: "Bob"
},
uid3: {
etc...
}
}
Run Code Online (Sandbox Code Playgroud)
我想按分数对它们进行排名,只保留前 100 名。
我是按照文档做到的。但它不起作用。即使分数发生变化,它也始终返回相同的顺序。
const query = firebase.database().ref('scores')
.orderByChild('score')
.limitToLast(100)
query.on('child_added', snapshot => {
const score = snapshot.val().score
console.log(score)
})
Run Code Online (Sandbox Code Playgroud)
我也在优化规则中添加了这一点,但我不确定它是否正确:
"scores": {
".indexOn": ["score"]
}
Run Code Online (Sandbox Code Playgroud)
正确的方法是什么?
我有一个进度条,它从数组中获取其值,如下所示:
users = [
{
"name": "Tim Jones",
"email": "timjones_1965@gmail.com",
"photo": "assets/images/tim-jones.jpg",
"progress": "50"
},
Run Code Online (Sandbox Code Playgroud)
还有进度条
<mat-progress-bar mode="determinate" value="{{user.progress}}"></mat-progress-bar>
Run Code Online (Sandbox Code Playgroud)
我想根据进度值显示不同的颜色:
Progress from 0% to 20% = red<br>
Progress from 21% to 50% = yellow<br>
Progress from 51% to 100% = green<br>
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!
我对 Angular 还很陌生,我的问题可能看起来很基本,但如果能提供一些指导,我将不胜感激。我目前正在编写一个应用程序来自学一些真正的开发技能。在我的应用程序中,我有一个 Angular 组件,它导入我编写的提供数据的服务。
这是我的组件
@Component({
selector: 'music-instrument-list',
templateUrl: './instrument-report.component.html',
styleUrls: ['./instrument-report.component.css']
})
export class InstrumentReportComponent implements OnInit, OnDestroy {
constructor(public apiService: ApiService) {}
public availableInstruments: any[];
ngOnInit() {
this.apiService.getInstruments().subscribe((result) => {
this.availableInstruments = result;
});
}
ngOnDestroy() {
// how do I unsubscribe?
}
}
Run Code Online (Sandbox Code Playgroud)
这非常简单,但如果我尝试添加this.apiService.getInstruments.unsubscribe()到ngOnDestroy块中,我会收到以下错误:Type => Observable' 上不存在 Property 'unsubscribe'。我什至考虑过在类似链接.unsubscribe()之后添加.subscribe(),但这只会使我的页面挂起。我也没有收到任何错误。有人可以告诉我如何最好地取消订阅吗?我是否需要将 api 调用分配给变量,然后在块中的变量名称上使用 .unsubscribe( ngOnDestroy)