我试图找出如何更改React-Native的TouchableOpacity组件的不透明度的体积,这意味着我不喜欢执行印刷时的不透明度的默认值,并且我希望不透明度不那么透明.
根据用于此目的的文档,应使用Animated API:
通过将子项包装在Animated.View中来控制不透明度,Animated.View将添加到视图层次结构中.请注意,这可能会影响布局.
所以,我做到了,这就是它的样子:
<Animated.View style={{ opacity: this.state.opacity._value }}>
<TouchableOpacity
onPress={this.hideKeyboard.bind(this)}
style={{ opacity: this.state.opacity._value }}
>
<Text style={buttonTextStyle}>Cancel</Text>
</TouchableOpacity>
</Animated.View>
Run Code Online (Sandbox Code Playgroud)
该hideKeyboard方法,正在被调用onPress,调用changeOpacity从内它的方法,这是它的外观:
changeOpacity() {
Animated.timing(
this.state.opacity,
{
toValue: this.state.opacity === 1 ? 0 : 1,
duration: 500
}
).start();
}
Run Code Online (Sandbox Code Playgroud)
this.state.opacity在构造函数中声明:
constructor(props) {
super(props);
this.state = { opacity: new Animated.Value(1) };
}
Run Code Online (Sandbox Code Playgroud)
拥有所有这些,行为(不透明度onPress of TouchableOpacity的音量)不会改变,它仍然保持默认.该文档还模糊地介绍了setOpacityTo方法,但由于文档中提供的描述的全面性,我无法弄清楚如何使用它.如何执行不透明度的手动配置?
我想旋转一个按钮.因此我写了以下代码:
public void show () {
skin2 = new Skin (Gdx.files.internal("SettingsButton.json"));
button2 = new Button(skin2);
button2.setPosition(25,1440);
button2.setSize(120,120);
button2.setOrigin(button2.getWidth() / 2, button2.getHeight() / 2);
button2.addAction(Actions.repeat(RepeatAction.FOREVER,
Actions.sequence(
Actions.rotateBy(360, 1),
Actions.rotateTo(0))));
button2.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
game.setScreen(new SettingsScreen(game));
super.clicked(event, x, y);
}
});
stage.addActor(button2);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,按钮没有旋转,但我不知道为什么.我该如何改进我的代码?
我正在使用此应用程序,用户可以将某些项目标记为收藏。我想使用心形按钮代替此功能,这可能吗?
我想在点击按钮后更改背景
var bm : Button = messeg
bm . setOnClickListener {
bm . background = R.color.green
}
Run Code Online (Sandbox Code Playgroud)
错误日志:
错误:(35,31)类型不匹配:推断类型是Int但可绘制!预计错误:任务':app:compileDebugKotlin'的执行失败.
编译错误.有关详细信息,请参阅日志
我在简单的屏幕底部添加了按钮,每当按下按钮时我都想滚动顶部.什么代码添加到按钮onPress?,请建议任何解决方案,提前谢谢.
我创建了一个名为gPaneCenter的gridPane,用于创建表.当我将一个项目添加到网格时,它将调用mehtod addRow(),请参阅下面的内容:
public static void addRow() {
System.out.println("Test");
Label prodDes = new Label(String.valueOf(Controller.shoppingCart.getOrder(i).getProduct().getDescription()));
Label prodPrice = new Label(String.valueOf(Controller.shoppingCart.getOrder(i).getProduct().getUnitPrice()));
Label prodQuant = new Label(String.valueOf(Controller.shoppingCart.getOrder(i).getQuantity()));
Label prodCost = new Label(String.valueOf(Controller.shoppingCart.getOrder(i).getCost()));
HBox quantityChanger = new HBox();
Button decreaseQuantBut = new Button("-");
Button increaseQuantBut = new Button("+");
decreaseQuantBut.setOnAction(e -> Controller.shoppingCart.getOrder(i).decreaseQuantity());
increaseQuantBut.setOnAction(e -> Controller.shoppingCart.getOrder(i).increaseQuantity());
quantityChanger.getChildren().addAll(decreaseQuantBut,prodQuant,increaseQuantBut);
View.gPaneCenter.addRow(l, prodDes,prodPrice,quantityChanger,prodCost);
l++;
i++;
}
Run Code Online (Sandbox Code Playgroud)
'i'和'l'在开始时声明:
static int i = 0;
static int l = 1;
Run Code Online (Sandbox Code Playgroud)
在添加项目时会生成以下GUI:
当我单击" - "按钮或"+"按钮时,我想减少数量并分别增加数量,但是当我点击任一按钮时出现以下错误:
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index: 1, Size: …Run Code Online (Sandbox Code Playgroud) 我有一个javascript函数来更改按钮单击时的按钮样式.
HTML
<button id="pause" class="pause" onclick="event_click_startpause(this);">Pause</button>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
window.event_click_startpause = function(btn) {
if (interval === null) {
start();
btn.innerText = 'pause';
btn.style.backgroundColor = "#c1580b";
btn.style.box-shadow= "0px 0px 0px 3px #173B0B"
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我想为按钮添加另一种样式.为此我也添加了这个
btn.style.box-shadow= "0px 0px 0px 3px #173B0B"
Run Code Online (Sandbox Code Playgroud)
是不是可以在此功能中添加多个样式?那么我该如何解决这个问题呢.
我想在我的游戏中创建一个可以控制背景音乐的按钮.第一次点击将停止背景音乐,第二次点击可以恢复音乐.现在我的按钮可以控制音乐的开启和关闭,但是我需要多次点击才能使它工作,似乎每次都没有捕获点击事件,这里是我的代码:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if 20 + 50 > mouse_position[0] > 20 and 20 + 20 > mouse_position[1] > 20:
play_music = not play_music
if play_music:
pygame.mixer.music.unpause()
else:
pygame.mixer.music.pause()
pygame.display.flip()
clock = pygame.time.Clock()
clock.tick(15)
Run Code Online (Sandbox Code Playgroud) 虽然标题解释了我的大多数问题,但您可能需要一些背景信息.我已经开发了一段时间的网站了.该网站上有3个按钮在不同颜色的每个部分.现在,是否有更有效的方法来执行以下操作:
/* Button 1 */
#button1 {
display: inline;
margin-left: 26px;
color: orangered;
border: 3px solid orangered;
box-sizing: border-box;
padding: 7px 30px 7px 30px;
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
}
#button1:hover {
background-color: orangered;
color: white;
}
/* Button 2 */
#button2 {
display: inline;
margin-left: 26px;
color: dodgerblue;
border: 3px solid dodgerblue;
box-sizing: border-box;
padding: 7px 30px 7px 30px;
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
}
#button2:hover {
background-color: dodgerblue;
color: white; …Run Code Online (Sandbox Code Playgroud)我是React Native的初学者。从图像中可以看到,我有一个Scroll View和两个按钮。我已经成功实现了滚动视图,该视图工作正常,但我也希望他们在按下按钮时自动滚动。我尝试了很多搜索,但没有得到任何有效的信息。因此,任何帮助表示赞赏。请在下面找到我的代码。
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View, Dimensions, ScrollView, Button } from 'react-native';
var screenWidth = Dimensions.get('window').width;
export default class App extends React.Component {
render() {
return (
<View style={styles.MainContainer}>
<View style={styles.ButtonViewContainer}>
<View style={styles.ButtonContainer}>
<Button title="Screen 1" />
</View>
<View style={styles.ButtonContainer}>
<Button title="Screen 2" />
</View>
</View>
<ScrollView
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
>
<View style={styles.ScrollContainer}>
<Text style={styles.ScrollTextContainer}>
Screen 1
</Text>
</View>
<View style={styles.ScrollContainer}>
<Text style={styles.ScrollTextContainer}>
Screen 2
</Text>
</View>
</ScrollView> …Run Code Online (Sandbox Code Playgroud)button ×10
android ×4
react-native ×3
css ×2
html ×2
java ×2
javascript ×2
reactjs ×2
background ×1
increment ×1
javafx ×1
kotlin ×1
libgdx ×1
onpress ×1
pygame ×1
python ×1
rotation ×1
scroll ×1
scrollview ×1
xml ×1