EditText 将颜色更改为自定义 ListView
EditText changes the color into a custom ListView
下图不是我正在开发的,但可以向您展示问题所在。
ListView
中的EditText
:
和同样的EditText
变成ListView
:
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;
}
有谁知道为什么这个 EditText
在我用到 ListView
时会改变颜色?
经过几个小时,我终于找到了问题所在。我不得不删除 getApplicationContext()
.
代码如下:
LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
而现在是如:
LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
下图不是我正在开发的,但可以向您展示问题所在。
ListView
中的EditText
:
和同样的EditText
变成ListView
:
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;
}
有谁知道为什么这个 EditText
在我用到 ListView
时会改变颜色?
经过几个小时,我终于找到了问题所在。我不得不删除 getApplicationContext()
.
代码如下:
LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
而现在是如:
LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);