小编Rob*_*met的帖子

OnClick事件仅在edittext上第二次运行

我有一个edittext,当用户点击这个edittext时,我想显示一个alertdialog.
我的代码如下:

            edt.setInputType(InputType.TYPE_NULL);
            edt.setFocusableInTouchMode(true);
            edt.requestFocus();

            edt.setCursorVisible(false);

            edt.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    CommentDialog.buildDialog(mContext, identifier, false, edt.getId());
                }
            });
Run Code Online (Sandbox Code Playgroud)

我不希望在用户单击edittext时显示键盘,因此我将inputtype设置为TYPE_NULL.
但是当edittext没有焦点并且我单击它时,onClick事件不会被执行.当我再次单击它时,alertdialog会正确显示.

我该如何解决?

android

53
推荐指数
5
解决办法
3万
查看次数

在锭床工人的文本是白色的在白色背景

我的微调器上的文字是白色的,我不知道为什么.

在此输入图像描述

这是我的xml,没什么特别的

 <Spinner
     android:id="@+id/spinner_date"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="1" />
Run Code Online (Sandbox Code Playgroud)

我的代码

dateSpinner = (Spinner) findViewById(R.id.spinner_date);
selectedDate = calendar.getTime();
List<String> list = new ArrayList<String>();
list.add(formatter.format(selectedDate));
dateAdapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item, list);
dateSpinner.setAdapter(dateAdapter);
Run Code Online (Sandbox Code Playgroud)

我的文字以白色显示的原因是什么?

编辑:我找到了原因,我替换了我的onCreate中设置的mContext参数.

mContext = getApplicationContext();
Run Code Online (Sandbox Code Playgroud)

现在我用d

ateAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, list);
Run Code Online (Sandbox Code Playgroud)

它的工作原理.

android adapter

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

找不到RippleDrawable

我想在代码中动态创建一个纹波.

码:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      buyButton.setBackground(getPressedColorRippleDrawable(primaryColor, darkerVariant));
}

public static RippleDrawable getPressedColorRippleDrawable(int color, int darkerVariant) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ColorStateList colorStateList = new ColorStateList(
                new int[][]
                        {new int[]{}},
                new int[]
                        {darkerVariant}
        );
        return new RippleDrawable(colorStateList, new ColorDrawable(color), null);
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

这适用于棒棒糖,但会使我的GNEX(4.3)上的应用程序崩溃.
错误:

找不到类'android.graphics.drawable.RippleDrawable',从方法片段引用.ProductDetailFragment.getPressedColorRippleDrawable

07-17 12:57:45.757 30992-30992/com.comizzo.ginsonline E/AndroidRuntime:致命例外:主要

java.lang.VerifyError:fragments/ProductDetailFragment

但RippleDrawable从未在Gnex上使用,因为代码未被执行.

我怎样才能解决这个问题 ?

android rippledrawable

11
推荐指数
2
解决办法
4万
查看次数

保持中风内的波纹

我试图创建一个ripple背景drawableButton一个行程.

这是我到目前为止:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#336699">

    <item>
        <shape android:shape="rectangle">

            <solid android:color="#998811" />

            <stroke
                android:width="2dp"
                android:color="#119988" />

        </shape>
    </item>
</ripple>
Run Code Online (Sandbox Code Playgroud)

但是通过这种解决方案,波纹与我的中风重叠.
我只想要ripple中风,我该怎么做?

android rippledrawable

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

不同的文本按钮

我想创建一个按钮.此按钮包含一个大小为22像素的字母和右侧的一些字母,大小为16像素.

像这样:
在此输入图像描述

我怎样才能做到这一点?

目前我有这个:

private void setText(Button btn, String text, String underText) {
    Spannable span = new SpannableString(text + "\n" +  underText);

    btn.setText(span);
}
Run Code Online (Sandbox Code Playgroud)

android text-formatting button

9
推荐指数
2
解决办法
5401
查看次数

这个LinearLayout应该使用android:layout_height ="wrap_content"?

我有以下xml布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" // ==> here I get the error.
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"  />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="2dip"
        android:background="#298EB5"
        android:orientation="horizontal" />


  </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

但是我收到了lint消息:

这个LinearLayout应该使用android:layout_height ="wrap_content"

为什么我收到此消息?

android

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

如何避免嵌套权重?

我有一个xml布局来输入密码:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FF000000"
    android:orientation="vertical"
    android:weightSum="1" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_margin="5dp"
    android:layout_weight="0.2"
    android:background="@android:drawable/edit_text"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/pinDisplay"
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="0.85"
        android:background="@null" />

    <ImageButton
        android:id="@+id/backspace"
        style="@android:style/Widget.Button"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical"
        android:layout_margin="3dp"
        android:layout_weight="0.15"
        android:gravity="center"
        android:src="@android:drawable/ic_input_delete" />
</LinearLayout>

<!-- Keypad section -->

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.8"
    android:baselineAligned="false"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="5dip"
        android:layout_marginRight="4dip"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/one"
            android:layout_width="0sp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="1"
            android:textAppearance="@android:attr/text" />

        <Button
            android:id="@+id/two"
            android:layout_width="0sp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="2" />

        <Button
            android:id="@+id/three"
            android:layout_width="0sp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="3" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

9
推荐指数
2
解决办法
5891
查看次数

How to add canvas xaml resource in usercontrol

I have downloaded this pack : http://modernuiicons.com/ and I'm trying to use the xaml icons.

I have added a xaml file to my solution with the following content

<?xml version="1.0" encoding="utf-8"?>
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_check" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
<Path Width="37.9998" Height="31.6665" Canvas.Left="19.0001" Canvas.Top="22.1668" Stretch="Fill" Fill="#FF000000" Data="F1 M 23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z "/>
</Canvas>
Run Code Online (Sandbox Code Playgroud)

Now, how do I reference this canvas to my usercontrol?

Usercontrol

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

更改日历项目的前景色

我正在自定义WPF中的日历控件,我可以调整背景颜色,标题前景色等.但我找不到如何编辑1-31天日历项目的外观.在

截图:

在此输入图像描述

如您所见,数字都是深灰色,几乎无法读取.我还想在鼠标悬停时摆脱蓝色叠加.

码:

<Window x:Class="WPFDatePickerSample.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="500" Width="500"
    Background="#2F2F2F">

<Window.Resources>
    <Style TargetType="{x:Type CalendarItem}">
        <Setter Property="Margin" Value="50"/>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CalendarItem}">
                    <ControlTemplate.Resources>
                        <DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
                            <TextBlock Foreground="#FFA9C822" FontWeight="Normal" FontSize="12" HorizontalAlignment="Center" Margin="0,5,0,5" Text="{Binding}" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </ControlTemplate.Resources>

                    <Grid x:Name="PART_Root">
                        <Grid.Resources>
                            <SolidColorBrush x:Key="DisabledColor" Color="#A5FFFFFF"/>
                        </Grid.Resources>

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="1">
                            <Border BorderBrush="#FFFFFFFF" BorderThickness="0" CornerRadius="0">
                                <Grid>
                                    <Grid.Resources>
                                        <ControlTemplate x:Key="PreviousButtonTemplate" TargetType="{x:Type …
Run Code Online (Sandbox Code Playgroud)

wpf calendar

7
推荐指数
2
解决办法
6167
查看次数

正则表达式与数字和特殊字符,但没有字母

我正在制作一个接受带有任何小数(0-9),+,*或#的输入的正则表达式,但不应接受任何字母(az).

所以数字就像

  • #192#
  • *31#+ 32475728966
  • 0479266315
  • 32495959511

应该被接受.

当字符串中有任何字母时,正则表达式无效.

  • #192#abbef
  • a0479266315

这是我到目前为止的正则表达式:

private const string PhoneNumberRegex = "((\\d)|(\\*)|(\\#)|(\\+))?";

private bool IsValid(inputString)
{
    // Accept * # + and number
    Match match = Regex.Match(inputString, PhoneNumberRegex, RegexOptions.IgnoreCase);
    return match.Success;
}
Run Code Online (Sandbox Code Playgroud)

但是这个正则表达式在#192#abbef上也会返回true

我怎样才能解决这个问题?

c# regex

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