小编Jac*_*lla的帖子

如何通过包含布局的数据绑定在 dp 中传递维度?

我正在尝试传递包含布局的 paddingTop 但我找不到方法。我尝试传递资源文件中定义的 dimen,一个 int,将变量类型设置为 int 并传递 dp,我发现它有效的唯一方法是将变量定义为 int 并传递 int。

这是包含的布局:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<data>

    <import type="android.view.View" />

    <variable
        name="image"
        type="android.graphics.drawable.Drawable" />

    <variable
        name="notification"
        type="int" />
    <variable
        name="paddingTop"
        type="androidx.annotation.Dimension" />

</data>

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:paddingTop="@{paddingTop}"
        android:layout_gravity="center">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingEnd="7dp"
            android:paddingBottom="7dp"
            tools:src="@drawable/ic_tab_home_selector"
            android:src="@{image}"/>

        <TextView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:background="@drawable/tab_notification_circle"
            android:fontFamily="@font/muli"
            android:gravity="center"
            android:text="@{String.valueOf(notification)}"
            android:textColor="@android:color/white"
            android:textSize="10sp"
            android:visibility="@{notification > 0 ? View.VISIBLE : View.GONE}" />


    </RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这就是我试图传递维度的方式:

 <include
            android:id="@+id/tab_home"
            layout="@layout/layout_tab_item"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:notification="@{1}"
            app:paddingTop="@{4dp}"
            app:image="@{@drawable/ic_tab_home_selector}"/>
Run Code Online (Sandbox Code Playgroud)

android include android-databinding

8
推荐指数
1
解决办法
1738
查看次数

如何在Android中为固定大小的字符串制作带下划线的Edittext字符?

我需要制作一个EditText,当用户添加新的下划线时,该下划线替换为char。像这样:

在此处输入图片说明

我做了类似的事情,用6个EditTexts(需要的String的大小)和一个'_'字符作为提示,当写一个a时将焦点移到下一个,而删除时将其焦点移到上一个,但我在删除或编辑未添加的最后一个字符时遇到问题。有人知道我该怎么做吗?

这是我在活动中的代码:

   private void manageFocus(final EditText beforeET, final EditText currenteET, final EditText afterET) {

       if (beforeET != null) {
           currenteET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
               @Override
               public void onFocusChange(View v, boolean hasFocus) {
                   if (hasFocus && beforeET != null && beforeET.getText().toString().length() < 1 && currenteET.getText().toString().equals("")) {
                       beforeET.requestFocus();
                   }
               }
           });
       }

       currenteET.addTextChangedListener(new TextWatcher() {
           @Override
           public void beforeTextChanged(CharSequence s, int start, int count, int after) {
           }

           @Override
           public void afterTextChanged(Editable s) {

           }

           @Override
           public void onTextChanged(CharSequence s, int start, int …
Run Code Online (Sandbox Code Playgroud)

android android-edittext

5
推荐指数
1
解决办法
1697
查看次数

隐藏工具栏,CoordinationLayout和Webview不起作用

我正在尝试使用新的CordinationLayout滚动WebView时隐藏工具栏,但它无法正常工作.有什么办法吗?这是我的xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.themobilebakery.isus.gui.WebViewActivity">

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <android.support.v7.widget.Toolbar
            android:id="@+id/webview_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:minHeight="0dp"
            app:layout_scrollFlags="scroll|enterAlways" />

        <ProgressBar
            android:id="@+id/webview_progress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:progressDrawable="@drawable/isus_orange_progres_webview"
            app:layout_scrollFlags="scroll|enterAlways" />
    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android toolbar webview

1
推荐指数
1
解决办法
3229
查看次数