当前位置:网站首页>Textfield and password input box that are more flexible and easy to use in compose
Textfield and password input box that are more flexible and easy to use in compose
2022-07-26 05:00:00 【Li Xiaobai LT】
Preface
Jetpack Compose Medium TextField Easy to use , But if you want to customize ui It's not easy to achieve , Let's see the effect :
TextField:


Similar to that OutlinedTextField:

They all have something in common api And features , Easy to use , But it has a large inner margin, which is difficult to adjust , And its background ui It's not easy to adjust ( The background can be changed to transparent , But I didn't change the source code to ...)
Luckily Compose The basic input box is reserved in :BasicTextField


No margins , No background , It is very suitable for us to customize ui, So I based on BasicTextField It encapsulates , send ui Easier to use
Text
First, let's see how to use it and its effect


Then there is the basis GoodTextField Encapsulated for password input PasswordTextField


then api Basic and ordinary TextFild No difference , Just briefly talk about the extra api
/**
* More convenient and easy to use TextField( Text input box )
* [value] The text in the input box
* [onValueChange] The change callback of the text in the input box
* [modifier] modification
* [hint] The content displayed when there is no text in the input box
* [maxLines] How many lines of text can be displayed at most
* [fontSize]text and hint Font size of
* [fontColor]text Font color for
* [maxLength] How many words can be displayed at most ,ps: Because the text will be truncated , It will cause the keyboard state to be reset when truncating (TextField characteristic )
* [contentAlignment]text and hint How
* [leading] The components shown on the left
* [trailing] The components shown on the right
* [background] background
* [horizontalPadding] Horizontal internal spacing
* [enabled] Can I input ,false Cannot input and copy
* [readOnly] Can I input ,true Unable to input , But it's replicable , Get focus , Move the cursor
* [textStyle] Font style
* [keyboardOptions] Keyboard configuration
* [keyboardActions] Keyboard callback
* [visualTransformation] Transformation of text presentation
* [onTextLayout] Callback executed when calculating the new text layout
* [interactionSource] State properties
* [cursorBrush] Cursor drawing
*/
@Composable
fun GoodTextField(
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
hint: HintComposeWithTextField? = null,
@IntRange(from = 1L) maxLines: Int = 1,
fontSize: TextUnit = 16.sp,
fontColor: Color = Color333,
maxLength: Int = Int.MAX_VALUE,
contentAlignment: Alignment.Vertical = Alignment.CenterVertically,
leading: (@Composable RowScope.() -> Unit)? = null,
trailing: (@Composable RowScope.() -> Unit)? = null,
background: BackgroundComposeWithTextField? = BackgroundComposeWithTextField.DEFAULT,
horizontalPadding: Dp = 16.dp,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
visualTransformation: VisualTransformation = VisualTransformation.None,
onTextLayout: (TextLayoutResult) -> Unit = {},
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
cursorBrush: Brush = SolidColor(MaterialTheme.colors.primary),
){}among background Property provides the ability to customize the background
hint Properties are similar to EditText Of hint attribute , But it is more flexible , You can use any Compose Components
maxLength Attribute can control how many words can be input at most
Introduce projects
In the root project build.gradle Add... To the document :
allprojects {
repositories {
maven { url 'https://jitpack.io' }
...
}
}app Of build.gradle Medium plus , Latest version reference :https://jitpack.io/#ltttttttttttt/ComposeViews
dependencies{
...
implementation 'com.github.ltttttttttttt:ComposeViews:1.0.9'
}Then you can use it happily GoodTextField and PasswordTextField 了
The project is open source , welcome star:GitHub - ltttttttttttt/ComposeViews
And there are more than GoodTextField, There are more easy to use Compose Components , such as :
Compose Medium ViewPager:ComposePager
Banner
FlowLayout
More will be added later Compose Components
end
边栏推荐
- SQL encryption and decryption injection details
- Use field parameters for report translation
- 【ACWing】1268. 简单题
- User defined type details
- 擅长C(暑假每日一题 6)
- Can serial port can 232 can 485 serial port to CANbus bus gateway module can232/485mb converter cancom
- [wp][gwctf 2019] boring lottery
- Two ways to create MySQL database
- The first open source MySQL native HTAP database in China will be released soon! Look at the three highlights first, limited to the surrounding areas, waiting for you~
- What are the characteristics of the grammar of Russian documents in the translation of scientific papers
猜你喜欢

Working principle and application of fast recovery diode

What is the difference between asynchronous and synchronous transmission signals (electronic hardware)
![[mathematical modeling] analytic hierarchy process (AHP)](/img/20/8ebd951a0e0c46d1967c6c8b078a4a.png)
[mathematical modeling] analytic hierarchy process (AHP)

columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by mysql8.0解决办法

【云原生 | 17】容器的四种网络模式

UE4 two ways to obtain player control

UE4 displays text when it is close to the object, and disappears when it is far away

Briefly describe the application fields of WMS warehouse management system

Recursive implementation of exponential enumeration

Excel VBA:实现自动下拉填充公式至最后一行
随机推荐
Phaser (I): platform jumping collection game
Soft exam review and plan
Codeforces Round #807 (Div. 2)
2022 Henan Mengxin League game (3): Henan University L - synthetic game
@Autowired注解的原理
域名解析过程全分析,就着文字理解更佳
data warehouse
迁移服务器,重新配置数据库(数据库无监听,启动监听报TNS-12545、TNS-12560、TNS-00515错误)
UE4 controls the rotation of objects by pressing keys
Ffmpeg video coding
IEC61131 数据类型与 C#数据类型的对应
[wp][gwctf 2019] boring lottery
CountLaunch Demo的测试
2022 a.static query on tree (tree section)
Is this my vs not connected to the database
擅长C(暑假每日一题 6)
2022河南萌新联赛第(三)场:河南大学 A - 玉米大炮
[mathematical modeling] analytic hierarchy process (AHP)
Face database collection summary
Ggjj, do you have a look at this problem? Does caching cause cross domain problems?