我试图升级我的Android项目以使用Android 5.0进行编译。在此之前,我正在成功使用appcompat-v7库。现在使用ActionBarActivity和Theme.AppCompat会导致我的分段布局中的视图不呈现或不可见。如果我将其更改回“活动”并删除appcompat主题,则视图将再次显示。任何人都可以指出我做错了的配置吗?我的Eclipse项目正在使用Android 5.0,专用库android-support-v4.jar和android-support-v7-appcompat.jar进行编译。在Android依赖项下是android-support-v7-appcompat.jar。Appcompat v7 Android 5.0 ActionBarActivity TextView不可见
而且我有下面的代码:
在AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?><!DOCTYPE something>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.ctest"
android:versionCode="33"
android:versionName="1.4.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="18"/>
<application
android:icon="@drawable/ic_launcher"
android:label="My App"
android:allowBackup="true" >
<activity
android:name=".MyActivity"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在fragment_layout.xml:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE something>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Nothing here"
android:textColor="@color/blue" >
</TextView>
</LinearLayout>
在MyActivity.java:
package com.mycompany.ctest;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class MyActivity extends ActionBarActivity {
private FragmentManager mFM;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFM = getFragmentManager();
mFM.beginTransaction()
.add(android.R.id.content, new MyFragment(),"frag")
.commit();
}
}
而且, MyFragment.java:
package com.mycompany.ctest;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MyFragment extends Fragment {
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved) {
return inflater.inflate(R.layout.fragment_layout,group,false);
}
}
编辑:logcat的显示 10月12日至13日:10:09.709:E /的ResourceType(1013):风格包含错误项重点:0x01010479
虽然我认为一定是不相关的,因为如果我添加一个活动布局与加载的静态片段,而不是使用片段管理器,我的视图变得可见。而且我仍然收到带有错误输入消息的Style contains键。
我更改为MyFragment中的v4 Fragment和MyActivity中的v4 FragmentManager。另外,我更改为getSupportFragmentManager。仍然没有运气 – mary 2014-12-13 16:07:59