我用库创建了一个库活动。 这个库是库: https://github.com/mikepenz/AboutLibraries
如果我试图替换我创建的片段(我创建了相关的,我很确定),问题是我得到了安全错误
这是活动
public class LibrariesActivity extends AppCompatActivity {
public static AppCompatActivity activity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_libraries);
// Set up the action bar.
Toolbar toolbar = (Toolbar) findViewById(R.id.barlibraries); // Attaching the layout to the toolbar object
toolbar.setNavigationIcon(R.drawable.ic_back);
toolbar.setTitle(R.string.libraries_title);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
LibsFragment fragment = new LibsBuilder()
.withLibraries("gitty_reporter", "appintro", "aboutlibraries") // definitions in strings.xml
.withExcludedLibraries("androideasingfunctions")
.withAutoDetect(true)
.withLicenseShown(true)
.withVersionShown(false)
.withListener(new LibsConfiguration.LibsListener() {
@Override
public void onIconClicked(View view) {
}
@Override
public boolean onIconLongClicked(View view) {
return false;
}
@Override
public boolean onLibraryAuthorClicked(View v, Library library) {
return true;
}
@Override
public boolean onLibraryBottomClicked(View v, Library library) {
return true;
}
@Override
public boolean onLibraryAuthorLongClicked(View v, Library library) {
return true;
}
@Override
public boolean onLibraryBottomLongClicked(View v, Library library) {
return true;
}
@Override
public boolean onLibraryContentClicked(View v, Library library) {
return false;
}
@Override
public boolean onExtraClicked(View v, Libs.SpecialButton specialButton) {
return false;
}
@Override
public boolean onLibraryContentLongClicked(View v, Library library) {
return true;
}
})
.fragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction.replace(R.id.about_libraries_container,fragment).commit();
}
}
当我尝试替换时,我得
错误:预计在此行:
fragmentManager.beginTransaction().replace(R.id.about_libraries_container,fragment).
"()"
出错
有什么问题? 我搜索了很多,但还没有找到解决方案。 感谢帮助,谢谢
答案 0 :(得分:1)
LibsFragment
扩展了android.app.Fragment
,但您使用的android.support.v4.app.FragmentManager
仅适用于android.support.v4.app.Fragment
。
此库包含LibsFragment
,android.support.v4.app.Fragment
- LibsSupportFragment
。
解决方案是将LibsFragment
替换为LibsSupportFragment
,将.fragment()
替换为.supportFragment()
。有关此here的更多信息。