我的 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。我也应该手动将视图背景设置为黑色吗?或者主题中的黑色是否可以由系统上的用户自定义?(我不是安卓用户)。
谢谢