我的Android应用程序启动到BeginActivity这是SherlockFragmentActivity的子类,显示它是一个使用第一种观点:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
Fragment f = LoginFragment.newInstance();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, f, "loginfragment")
.attach(f)
.commit();
}
}
LoginFragment表明这样的观点:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.login, container, false);
// Get pointers to text views
usernameField = (EditText) v.findViewById(R.id.usernameLog);
passwordField = (EditText) v.findViewById(R.id.passwordLog);
progressBar = (ProgressBar) v.findViewById(R.id.progressBarLog);
// Set button click listeners for both buttons
Button b = (Button) v.findViewById(R.id.loginButton);
b.setOnClickListener(this);
return v;
}
点击登录时,我表现出这样的列表视图:
BeginActivity top = (BeginActivity) getActivity();
Fragment f = OfferListFragment.newInstance();
top.getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, f, "offerList")
.addToBackStack(f.getClass().getSimpleName())
.commit();
最后,OfferListFragment显示这样其视图:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.offers, container, false);
return v;
}
现在我遇到的问题是,最终OfferListFragment似乎是透明的,我可以看到下方的登录屏幕。 我使用的是有一个黑色的背景Theme.Sherlock。 我应该手动设置视图的背景的黑也? 或将在主题黑色是由系统上的用户自定义的? (我不是一个Android用户)。
谢谢