android studio拖拽控件。##1、Picker 是什么?
Picker提供了滑動選擇器,允許用戶從預定義范圍中進行選擇。
<Pickerohos:id="$+id:test_picker"ohos:height="match_content"ohos:width="300vp"ohos:background_element="#E1FFFF"ohos:layout_alignment="horizontal_center"ohos:normal_text_size="16fp"ohos:selected_text_size="16fp"/>
Picker picker = (Picker) findComponentById(ResourceTable.Id_test_picker);
picker.setMinValue(0); // 設置選擇器中的最小值
picker.setMaxValue(6); // 設置選擇器中的最大值
picker.setValueChangedListener((picker1, oldVal, newVal) -> {// oldVal:上一次選擇的值; newVal:最新選擇的值
});
picker.setFormatter(i -> {String value;switch (i) {case 0:value = "Mon";break;case 1:value = "Tue";break;case 2:value = "Wed";break;case 3:value = "Thu";break;case 4:value = "Fri";break;case 5:value = "Sat";break;case 6:value = "Sun";break;default:value = "" + i;}return value;
});
picker.setDisplayedData(new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"});
(1)設置文本樣式
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:background_element="black"ohos:orientation="vertical"><Pickerohos:id="$+id:test_picker"ohos:height="match_content"ohos:width="300vp"ohos:background_element="#E1FFFF"ohos:layout_alignment="horizontal_center"ohos:normal_text_size="16fp"ohos:normal_text_color="#FFA500"ohos:selected_text_size="16fp"ohos:selected_text_color="#00FFFF"/></DirectionalLayout>
Picker picker = (Picker) findComponentById(ResourceTable.Id_test_picker);picker.setDisplayedData(new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"});//設置文本樣式
picker.setNormalTextFont(Font.DEFAULT_BOLD);
picker.setNormalTextSize(40);
picker.setNormalTextColor(new Color(Color.getIntColor("#FFA500")));
picker.setSelectedTextFont(Font.DEFAULT_BOLD);
picker.setSelectedTextSize(40);
picker.setSelectedTextColor(new Color(Color.getIntColor("#00FFFF")));
(2) 設置所選文本的上下邊框
<Picker...ohos:bottom_line_element="#40E0D0"ohos:top_line_element="#40E0D0"/>
//創建 shape 對象
ShapeElement shape = new ShapeElement();
//設置矩形
shape.setShape(ShapeElement.RECTANGLE);
//設置顏色
shape.setRgbColor(RgbColor.fromArgbInt(0xFF40E0D0));
// 單獨設置上邊框
// picker.setDisplayedLinesTopElement(shape);
// 單獨設置下邊框
// picker.setDisplayedLinesBottomElement(shape);
// 同時設置上下邊框
picker.setDisplayedLinesElements(shape, shape);
(3)設置Picker的著色器顏色
<Picker...ohos:shader_color="#1E90FF"/>
picker.setShaderColor(new Color(Color.getIntColor("#1E90FF")));
(4)設置Picker中所選文本邊距與普通文本邊距的比例
<Picker...ohos:selected_normal_text_margin_ratio="5.0">
</Picker>
picker.setSelectedNormalTextMarginRatio(5.0f);
(5)設置選擇輪模式
該模式是來決定Picker是否是循環顯示數據的。
<Picker...ohos:wheel_mode_enabled="true"/>
picker.setWheelModeEnabled(true);
Picker 更多詳情
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态