小编Nou*_*n H的帖子

Android:选择器中未显示的禁用按钮的textColor?

我正在尝试使用选择器创建一个按钮,我的按钮可以具有以下状态:

  • 启用/禁用
  • 按下/未按下

根据上述状态.我需要操纵按钮:

  • 文字颜色
  • 背景图片

该按钮从我被禁用开始,因此它应该具有禁用的textColor和禁用的按钮背景.但我可以看到默认的textColor(在样式中指定)和没有背景图像!

这是我的选择器button_selector.xml

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

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

    <item android:state_pressed="false"
        android:state_enabled="false"
        android:textColor="#9D9FA2"
        android:drawable="@drawable/button" />    

    <item android:state_pressed="true"
        android:state_enabled="true"
        android:drawable="@drawable/button_pressed"/>

    <item android:state_pressed="true"
        android:state_enabled="false"
        android:textColor="#9D9FA2"
        android:drawable="@drawable/button"/>

    <item android:state_pressed="false"
        android:state_enabled="true"
        android:drawable="@drawable/button"/>    

</selector>
Run Code Online (Sandbox Code Playgroud)

这是我的layout.xml中的按钮声明

    <Button android:id="@+id/reserve_button"
        android:text="@string/reserve_button"
        android:layout_width="120dp"
        android:layout_height="40dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="20dp"
        android:paddingRight="15dp"
        android:layout_gravity="left"
        style="@style/buttonStyle"
        android:background="@drawable/button_selector" />
Run Code Online (Sandbox Code Playgroud)

最后这是我的风格(我的默认textColor设置)

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

 <resources>

     <style name="buttonStyle">
      <item name="android:textStyle">bold</item>
      <item name="android:textColor">#282780</item>
      <item name="android:textSize">18sp</item>
     </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

请帮忙!

xml android button background-image selector

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

Android:Android 4.1模拟器从DatePicker对话框调用onDateSet两次

我的应用程序在我的Android 2.2模拟器上完美运行.然后我决定在Android 4.1模拟器上进行测试.该DatePickerDialog看起来有点不同,因为当我按下"完成"某些原因,onDateSet()听众被调用两次,导致我的应用程序的问题.

我知道这一点,因为每当我点击"完成"时,代码中显示的日志就打印了两次

mDateSetListener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Log.v("onDateSet", "ENTERED");
            //rest of code...
    }};
Run Code Online (Sandbox Code Playgroud)

Android 2.2 DatePicker

使用Android 2.2 DatePicker

Android 4.1 DatePicker

不能使用Android 4.1 DatePicker

android datepicker emulation android-4.2-jelly-bean

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

无法在Mac模拟器上键入editText

我是新的Mac OS用户,在安装Eclipse和所有必要的要求之后,我将我的Android项目转移到了Mac.我的应用程序正常运行,但我似乎无法在模拟器中输入.

我使用Eclipse Juno运行Android 4.1模拟器.

macos android android-emulator android-edittext

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

Android:Spinner文本对齐到右边但没有居中

我完成了我的应用程序的英文版本,现在我正在进行阿拉伯语本地化.阿拉伯语是一种从右到左的语言,所以我需要在布局中调整很多东西,包括我的微调器显示.

我使用了Android中提到的相同方法- 在Spinner中将文本推向左侧但我将引力设置为右侧.

这是我的spinner_item.xml

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

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:layout_width="fill_parent"
    android:gravity="right" />
Run Code Online (Sandbox Code Playgroud)

改变了我的代码

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Run Code Online (Sandbox Code Playgroud)

对此

adapter.setDropDownViewResource(R.layout.spinner_item);
Run Code Online (Sandbox Code Playgroud)

我希望我的微调器看起来像我下面的老式英式旋转器,

英国旋转器

但它目前看起来像这样,

阿拉伯语旋转器

如何恢复以下内容:

  1. 单选按钮
  2. 文字大小越大
  3. 我希望它显示在右边,但是在两个分隔线之间居中.

注意阿拉伯语Web服务尚未完成,这就是图像中的数据仍为英语的原因.

UPDATE

在尝试了Adil Soomro的建议后,我得到以下信息,

旋转器半渴望

没有单选按钮,边框和第一个字母之间有相当大的空间.

UPDATE

在Adil Soomro编辑之后,我现在有了以下内容,

Spinner阿拉伯语固定

layout android arabic

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

Android:自定义适配器与自定义微调器下拉xml布局给出错误

我有一个带有自定义适配器的微调器,我用它来设置微调器中第一个元素的高度下降到零.我这样做是为了在我的微调器(第一个元素)中有一个默认消息,而用户无法单击它,因为它不可见.

package org.digitalhealthagency.elaj.util;

import java.util.ArrayList;

import org.digitalhealthagency.elaj.gui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class CustomAdapter extends ArrayAdapter implements SpinnerAdapter{

    Context context;
    int textViewResourceId;
    ArrayList arrayList;

    public CustomAdapter(Context context, int textViewResourceId,  ArrayList arrayList) {
        super(context, textViewResourceId, arrayList);

        this.context = context;
        this.textViewResourceId = textViewResourceId;
        this.arrayList = arrayList;

    }

    @Override
     public View getDropDownView(int position, View convertView, ViewGroup parent){
       if (convertView == null)
       {
         LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         //convertView = vi.inflate(android.R.layout.simple_spinner_dropdown_item, null);
         convertView = …
Run Code Online (Sandbox Code Playgroud)

android spinner layout-inflater custom-adapter

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

EditText中的可点击复合可绘制,在单击时弹出视图

我正在使用TextWatcher验证我的输入,我希望我的红色提示图像可以点击,这样我就可以给用户提供视觉反馈,如下图所示.到目前为止,我输入的是当我输入无效数据时出现红色提示图像的编辑文本.我现在想知道如何使这个红色提示可点击并使弹出提示显示如图所示.

EditText提示

这是我到目前为止的代码,

public class MainActivity extends Activity implements TextWatcher{

    EditText username,email = null;
    boolean flag=false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);      

        username=(EditText) findViewById(R.id.usernametxt);
        email=(EditText) findViewById(R.id.emailtxt);

        username.addTextChangedListener(this);

        username.setOnTouchListener(new View.OnTouchListener(){
        public boolean onTouch(View view, MotionEvent motionEvent) {
            // your code here...
            if(flag)
            {
                email.setText("Error. . .");
            }
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);                
            return false;
            }
        });

        Button loginbtn = (Button) findViewById(R.id.login);
        loginbtn.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                //Check Validations
                if(username.getText().toString().equalsIgnoreCase(""))
                {
                    username.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.alert, 0);
                    flag=true;
                } …
Run Code Online (Sandbox Code Playgroud)

android textwatcher android-edittext

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

Android:Spinner选择对齐左侧

我完成了我的应用程序的英文版本,现在我正在进行阿拉伯语本地化.阿拉伯语是一种从右到左的语言,所以我需要在布局中调整很多东西,包括我的微调器显示.

当我从微调器选择菜单中选择一个项目时,我看到以下内容,

微调器选择

如您所见,"过敏"与旋转箭头的左侧和顶部对齐.我需要它与右边对齐.

注意阿拉伯语Web服务尚未完成,这就是图像中的数据仍为英语的原因.

编辑

Spinner mSpecialtySpinner = (Spinner) findViewById(R.id.specialty_appointment_spinner);
        ArrayAdapter<Specialty> adapter = new ArrayAdapter<Specialty>(AppointmentReservationActivity.this,android.R.layout.simple_spinner_item, specialities);
        adapter.setDropDownViewResource(R.layout.spinner_item);
        mSpecialtySpinner.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

layout android arabic gravity spinner

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

textColor以样式定义,未应用于按钮文本

我的应用程序中有几个按钮,我想将样式应用于所有这些按钮.

以下是我放在我的values文件夹中的styles.xml文件.

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

 <resources>

     <style name="buttonStyle">
      <item name="android:textStyle"> bold </item>
      <item name="android:textColor"> #282780 </item>
      <item name="android:textSize"> 20sp </item>
     </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

在我的布局xml文件中,我使用按钮内的样式如下,

<Button android:id="@+id/ok_preview_appointment_button" 
        android:text="@string/ok_preview_appointment_button"
        android:layout_width="175dp"
        android:layout_height="35dp"
        android:layout_marginBottom="10dp"
        style="@style/buttonStyle"
        android:background="@drawable/button_background" />
Run Code Online (Sandbox Code Playgroud)

我收到以下错误"java.lang.NumberFormatException:颜色值'#282780'必须以#开头"

我检查了其他线程,但他们似乎都遇到这个问题,当他们使用@color,这不是我的情况.

先感谢您!

java android styles colors button

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