【问题标题】:How to add custom features to Android soft keyboard如何为 Android 软键盘添加自定义功能
【发布时间】:2021-10-03 22:04:11
【问题描述】:

我正在开发一个关于原生 Android 的辅助项目。 我想在这篇文章所附的图片中添加该功能。我想知道如何在Android中实现这个功能以及它通常被称为什么。 请帮我。 谢谢Example of what I am intending to achieve

【问题讨论】:

    标签: android xml kotlin android-layout


    【解决方案1】:

    您可以通过使用带有android:gravity="bottom"FrameLayout 和带有适当约束的嵌套LinearLayoutConstraintLayout 并表示LinearLayout 来实现这一点。

    FrameLayout 为例

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">
        
        <androidx.appcompat.widget.Toolbar
            android:background="@color/lightGrey"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    
    
        <LinearLayout
            id="@+id/bottomToolbar"
            android:layout_gravity="bottom"
            android:gravity="center"
            android:foregroundGravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
        </LinearLayout>
    </FrameLayout>
    

    结果

    ConstraintLayout 为例

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <androidx.appcompat.widget.Toolbar
            app:layout_constraintTop_toTopOf="parent"
            android:background="@color/lightGrey"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    
    
        <LinearLayout
            id="@+id/bottomToolbar"
            app:layout_constraintBottom_toBottomOf="parent"
            android:gravity="center"
            android:foregroundGravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
            <Button
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Btn"/>
    
        </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    结果

    我用过按钮,但你明白要点,你可以使用 ImageButtons、图像、文本,随便你。

    除此之外,您还可以聆听“软键盘”的出现和消失,并为height 或底部工具栏的可见性设置动画,使其看起来更酷。 IE:当它出现时显示底部栏,当它消失时将其删除。

    【讨论】:

      猜你喜欢
      • 2016-05-29
      • 2015-11-13
      • 2011-07-25
      • 2016-04-09
      • 2011-10-24
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多