小编ABV*_*ita的帖子

确定iOS设备是否支持TouchID而不设置密码

我目前正在开发一个iOS应用程序,使用户可以使用TouchID登录应用程序,但首先他们必须首先在应用程序内设置密码.问题是,要显示设置密码选项以启用TouchID登录,我需要检测iOS设备是否支持TouchID.

使用LAContext和canEvaluatePolicy(如此处的答案如果设备支持Touch ID),如果用户在其iOS设备上设置了密码,我可以确定当前设备是否支持TouchID .这是我的代码片段(我使用的是Xamarin,所以它在C#中):

static bool DeviceSupportsTouchID () 
{
    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
    {
        var context = new LAContext();
        NSError authError;
        bool touchIDSetOnDevice = context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError);

        return (touchIDSetOnDevice || (LAStatus) Convert.ToInt16(authError.Code) != LAStatus.TouchIDNotAvailable);
    }

    return false;
}
Run Code Online (Sandbox Code Playgroud)

如果用户尚未设置设备密码,则无论设备是否实际支持TouchID ,authError都将返回" PasscodeNotSet "错误.

如果用户的设备支持TouchID,我想在我的应用程序中始终显示TouchID选项,无论用户是否在其设备上设置了密码(我只是警告用户首先在他们的设备上设置密码).反之亦然,如果用户的设备不支持TouchID,我显然不想在我的应用程序中显示TouchID选项.

所以我的问题是,无论用户是否在其设备上设置了密码,是否有一种很好的方法可以始终如一地确定iOS设备是否支持TouchID?

我能想到的唯一解决方法是确定设备的体系结构(在确定iOS设备是32位还是64位时可以回答),因为只有具有64位体系结构的设备才支持TouchID.但是,我正在寻找是否有更好的方法来做到这一点.

先谢谢!:)

iphone ipad ios xamarin touch-id

21
推荐指数
3
解决办法
2万
查看次数

如何在Android KeyboardView中实现涟漪效应?

我一直试图找到一种方法来在按下时在KeyboardView键上实现涟漪效果.听起来很简单,但我已经尝试了所有添加涟漪的方法,这些方法适用于其他类型的视图(列表视图,按钮等),但根本没有成功.

我的目标是创建一个数字小键盘,看起来像股票计算器应用程序中的键盘,默认情况下在Lollipop OS中出现:

股票棒棒糖计算器

在GitHub中有一个类似的计算器应用程序(https://github.com/numixproject/com.numix.calculator),它的键盘有一个连锁反应,但是当我读到代码时,似乎它使用了数字键的按钮而不是一个KeyboardView.

我希望使用KeyboardView可以实现连锁效果,因为我的应用程序已经使用KeyboardView实现了自定义数字键盘,我不想将其更改为使用按钮.

我尝试将keyBackground样式添加到样式中,如下所示:

<android.inputmethodservice.KeyboardView
    android:id="@+id/numeric_keypad"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    style="@style/my_numeric_keypad" />
Run Code Online (Sandbox Code Playgroud)

然后在themes.xml中:

<style name="my_numeric_keypad">
    <item name="android:keyTextSize">30dp</item>
    <item name="android:fontFamily">roboto</item>
    <item name="android:keyBackground">@drawable/numeric_keypad_ripple</item>
    <item name="android:keyTextColor">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后在drawable-v21文件夹中的numeric_keypad_ripple.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<ripple 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item android:drawable="@drawable/numeric_keypad_states"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)

numeric_keypad_states.xml是具有按下状态的旧选择器(它曾经被直接声明为keyBackground属性):

<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/numeric_keypad_pressed" />
    <item android:drawable="@drawable/numeric_keypad_normal" />
</selector>
Run Code Online (Sandbox Code Playgroud)

numeric_keypad_pressed.xml和numeric_keypad_normal.xml只是每个特定状态颜色的drawable,就像这样(两者完全相同,只是颜色属性不同):

<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/numeric_keypad_pressed_color"/>
        </shape>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

我认为上面的方法会起作用; 但事实并非如此.在我的Lollipop设备中,当我按下键盘时,它只显示正常按下的颜色而没有任何波纹,没有波纹的旧实现没有区别.我已经尝试删除该层,因为我认为它与波纹重叠,但仍然无法正常工作.在纹波上添加掩码也不起作用.

我也尝试使用rippledrawable作为选择器中的按下状态drawable而不是包装选择器,但它仍然无法正常工作.也尝试使用?android:attr/selectableItemBackground而不是rippledrawable但也无法正常工作.

哦,我实际上是在Xamarin而不是原生的Android上开发应用程序,但我认为这不应该有任何区别. …

android material-design rippledrawable android-5.0-lollipop

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