我有两个简单的列表视图,两者都加载了simple_list_view_item_1
。
问题在于,在一个文本中,文本是黑色的,而另一个是浅灰色。 我认为这个列表视图的样式有默认参数。
唯一的区别是第一个是活动而另一个是片段。一切都很好,但文字的颜色。为什么会这样?
编辑1:
活动代码:
public class Categoria_Divulgacion_Cientifica extends ListActivity {
protected String[] mResumenesDivulgacionCientifica;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_categoria__divulgacion_cientifica);
// Buscar AdView como recurso y cargar una solicitud.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Resources resources = getResources();
mResumenesDivulgacionCientifica = resources.getStringArray(R.array.titulos_divulgacion_cientifica);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mResumenesDivulgacionCientifica);
setListAdapter(adapter);
final String[] links = getResources().getStringArray(R.array.links_divulgacion_cientifica);
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String content = links[position];
Intent showContent = new Intent(getApplicationContext(),lectura_view.class);
showContent.setData(Uri.parse(content));
startActivity(showContent);
}
});
}
片段中的代码:
ublic class Seccion2 extends ListFragment {
protected String[] mNovedades;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.seccion2, container, false);
return rootView;
}
@Override
public void onResume() {
super.onResume();
// Buscar AdView como recurso y cargar una solicitud.
AdView adView = (AdView)this.getView().findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Resources resources = getResources();
mNovedades = resources.getStringArray(R.array.titulos_novedades);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (getActivity().getApplicationContext(),
android.R.layout.simple_list_item_1, mNovedades);
setListAdapter(adapter);
final String[] links = getResources().getStringArray(R.array.links_novedades);
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String content = links[position];
Intent showContent = new Intent(getActivity().getApplicationContext(),lectura_view.class);
showContent.setData(Uri.parse(content));
startActivity(showContent);
}
});
}
活动XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.estudiable.estudiable.Categoria_Emprendimiento"
android:background="@color/blanco">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="@dimen/layout_margin"
android:layout_marginBottom="@dimen/layout_margin_bottom"
android:paddingBottom="@dimen/padding_bottom_listview"
android:clipToPadding="false"
android:divider="@color/naranja_tigre_2"
android:dividerHeight="2px"
android:layout_centerVertical="true"/>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-XXXX"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
片段XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.estudiable.estudiable.Seccion2"
android:background="@color/blanco">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="@dimen/layout_margin"
android:layout_marginBottom="@dimen/layout_margin_bottom"
android:paddingBottom="@dimen/padding_bottom_listview"
android:clipToPadding="false"
android:divider="@color/naranja_tigre_2"
android:dividerHeight="2px"
android:layout_centerVertical="true"
tools:listitem="@android:layout/simple_list_item_1" />
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-XXX"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"/>
</RelativeLayout>enter code here
答案 0 :(得分:0)
将getActivity().getApplicationContext()
课程的Seccion2
更改为getActivity()
。
不要使用应用程序上下文来扩充视图,您将获得未经授权的视图。