EditText将颜色更改为自定义ListView

时间:2015-04-10 19:46:57

标签: android android-layout listview android-listview android-custom-view

以下图片并非我正在开发的内容,但可以向您显示问题。

EditText中的ListView

enter image description here

同样EditText加入ListView

enter image description here

ListView layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:background="@drawable/back_login"
    android:padding="20dp"
    android:layout_height="match_parent">

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/login"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        android:background="@color/white"
        android:drawableLeft="@drawable/ic_txt_user"
        android:padding="10dp"
        android:drawablePadding="5dp"
        android:textColorHint="#CCCCCC"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/password"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:background="@color/white"
        android:drawableLeft="@drawable/ic_txt_senha"
        android:padding="10dp"
        android:drawablePadding="5dp"
        android:password="true"
        android:textColorHint="#CCCCCC"/>

</LinearLayout>

我的ListView

<ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

最后我的适配器的getView()

    @Override
public View getView(int position, View view, ViewGroup viewGroup) {

    if (view == null) {

        LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getApplicationContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);

        view = _layoutInflater.inflate(R.layout.activity_login, viewGroup, false);

        mHolder = new ViewHolder();

        view.setTag(mHolder);

    }
    else {

        mHolder = (ViewHolder) view.getTag();

    }

    return view;

}

任何人都知道为什么EditTextListView中使用它时会改变颜色?

1 个答案:

答案 0 :(得分:1)

几个小时后我终于发现了问题。我不得不删除getApplicationContext()

代码如下:

LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getApplicationContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);

现在就是这样:

LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);