小编Kar*_*uri的帖子

自定义Android pin码输入小部件

我正在尝试为android创建一个自定义pin代码小部件,作为仅使用EditText带有密码inputType属性的替代方法.我想要显示的是一排盒子,并在用户键入其针脚时填充每个盒子.

其他人做了类似这样的事情,但事实证明这是一个固定数量的EditText视图,并且当字符被输入或删除时,有很多丑陋的代码用于交换焦点.这不是我想采取的方法; 相反,我正在设计我的可定制长度(简单)并且表现为单一的可聚焦视图(不那么容易).

到目前为止,我的概念是LinearLayout(保持"盒子")和EditText(存储用户输入)之间的某种混合.

到目前为止这是代码......

public class PinCodeView extends LinearLayout {
    protected static final int MAX_PIN_LENGTH = 10;
    protected static final int MIN_PIN_LENGTH = 1;

    protected int pinLength;
    protected EditText mText;

    public PinCodeView(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PinCodeView);
        try {
            pinLength = a.getInt(R.styleable.PinCodeView_pinLength, 0);
        } finally {
            a.recycle();
        }

        pinLength = Math.min(pinLength, MAX_PIN_LENGTH);
        pinLength = Math.max(pinLength, MIN_PIN_LENGTH);

        setupViews();

        Log.d(TAG, "PinCodeView …
Run Code Online (Sandbox Code Playgroud)

android widget

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

在自定义视图中绘制时支持 RTL 语言环境

当我使用 Canvas 在我的自定义视图中绘制时,是否有一种简单的方法可以在不手动反转坐标计算的情况下为 RTL 区域设置绘制?

作为一个非常人为的例子,这是一个自定义视图,在 onDraw() 中包含以下内容:

int w = getWidth();
int h = getHeight();
canvas.save();

mPaint.setColor(Color.RED);
canvas.drawRect(0, 0, w / 2, h, mPaint);
mPaint.setColor(Color.BLUE);
canvas.drawRect(w / 2, 0, w, h, mPaint);

int size = h / 4;
mPaint.setColor(Color.GREEN);
int paddingEnd = ViewCompat.getPaddingEnd(this);
canvas.translate(-paddingEnd, getPaddingTop());
canvas.drawRect(w - size, 0, w, size, mPaint);

canvas.restore();
Run Code Online (Sandbox Code Playgroud)

它在 LTR 和 RTL 布局中看起来完全相同:

在此处输入图片说明

我知道您可以使用矩阵或 canvas.scale(),但是对于更复杂的场景,例如在画布上绘制文本或其他可绘制对象,这不是一个可行的选择。

在 Canvas 上完成 RTL 绘图的最佳方法是什么?我真的必须计算 X 轴坐标的倒置值吗?

android android-custom-view right-to-left

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

如何以编程方式打开和关闭layout_behavior行为?

让我们假装简单的简单案例.我有一个FloatingActionButton,我在其上添加了layout_behavior.我需要能够以编程方式启用或禁用该行为.我怎么做?我最初通过xml添加行为

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/mine"
    app:backgroundTint="@color/colorPrimary"
    app:layout_anchor="@id/default_message"
    app:layout_anchorGravity="end|bottom"
    app:layout_behavior=“mywidget.ScrollingFABBehavior"/>
Run Code Online (Sandbox Code Playgroud)

android android-layout floating-action-button android-coordinatorlayout

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

如果我的Android Things应用程序没有UI,我是否需要使用后台线程?

我正在使用Android Things编写应用程序,并且大多数示例即使使用活动也不使用任何UI.我还需要为Android Things应用程序使用后台线程吗?

android android-things

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

Android:自定义视图上的通胀异常

我有一个自定义视图,使用这些构造函数扩展LinearLayout:

public class CustomView extends LinearLayout {

public CustomView(Context context) {
    this(context, null);
}

public CustomView(Context context, AttributeSet attrs) {
    this(context, attrs, R.attr.customViewStyle);
}

public CustomView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    /* set custom attributes with TypedArray */
}

    /* other methods */
}
Run Code Online (Sandbox Code Playgroud)

在我的/res/values/attrs.xml中:

<attr name="customViewStyle" format="reference" />

<declare-styleable name="CustomeView">
    <attr name="value" format="integer" />
    <attr name="android:imeOptions" />
    <attr name="android:imeActionId" />
    <attr name="android:imeActionLabel" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)

在我的/res/values/styles.xml中:

<style name="AppTheme" parent="@android:style/Theme.Black">
    <item name="android:windowBackground">@drawable/bg_dark_fiber</item>
    <item name="customViewStyle">@style/CustomViewStyle</item>
</style>

<style name="CustomViewStyle"> …
Run Code Online (Sandbox Code Playgroud)

android custom-controls nosuchmethoderror android-linearlayout inflate-exception

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

Android SQLite错误"没有这样的列",但列存在

当我尝试更新Android应用中的数据库行时出现错误.它似乎认为没有专栏last_update_time,但我绝对肯定有一个专栏.我已经创建并重新创建了几次数据库并检查了我的SQL语句,这个名称肯定有一个列.

一些日志声明:

02-13 14:31:09.508: I/Database(674): sqlite returned: error code = 1, msg = no such column: last_update_time

02-13 14:31:09.508: E/Database(674): Error updating icon=http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png last_update_time=1329172268604 distance=36.571194 _id=ba1f46d735746b66658bb970e842d647ea7f92d8 vicinity=3561 El Camino Real #75,
 Santa Clara name=Paris Baguette longitude=-121.994223 latitude=37.353605 types=bakery store food establishment reference=
 CnRlAAAAddN_wZD9BvHL0LCzxJUgzf_QcaFUVcIyDRPf26pRyrUVJ1yVkUkke420FEhwkaNfsZedlqrhaRJJwelopAYWEPRr7mAL81vivvlntYSSqS0xUxke655C7ay4AyOpaCO1BE7XbDmQSTV7WINl8c7W0hIQ_DXJBG0pSWe3P1gaJQOSuRoURMAs2eYOIzExARulJ7B7k5EK97c using UPDATE places SET icon=?,
 last_update_time=?, distance=?, _id=?, vicinity=?, name=?, longitude=?, latitude=?, types=?, reference=? WHERE _id = ba1f46d735746b66658bb970e842d647ea7f92d8

02-13 14:31:09.518: E/AndroidRuntime(674): android.database.sqlite.SQLiteException: no such column: last_update_time: , while compiling: UPDATE places SET icon=?,
 last_update_time=?, distance=?, …
Run Code Online (Sandbox Code Playgroud)

java database sqlite android

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