Android在启动时显示为空白屏幕

时间:2014-05-20 09:05:07

标签: android android-layout android-actionbar

我注意到当我在我的应用程序中使用操作栏时,当我启动应用程序时,会出现一个空白屏幕显示几秒钟,然后加载活动布局。有谁知道如何解决这个问题?

如果我不使用动作栏,这个空白的scren现在正在显示 这是我的一个例子:

public class Login extends Activity implements OnClickListener {

    private Button signInFacebook;

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        initWidgets();

    }

    private void initWidgets() {
        getActionBar().setBackgroundDrawable(
                getResources().getDrawable(R.drawable.nav_bg));

        getActionBar().setDisplayShowHomeEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(false);

        signInFacebook = (Button) findViewById(R.id.login_fb);
        signInFacebook.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {

        case R.id.login_fb:
            intent = new Intent(this, ChangePassword.class);
            startActivity(intent);
            break;
        }
    }
}

enter image description here

我没有得到任何错误或警告

3 个答案:

答案 0 :(得分:0)

只需在启动器活动中添加此行即可             机器人:主题=" @android:风格/ Theme.NoTitleBar"如下例

       <activity
        android:name="com.example.app.Login"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>

答案 1 :(得分:0)

使用requestWindowFeature

 public class Login extends Activity implements OnClickListener {

    private Button signInFacebook;

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.login);

        initWidgets();

    }

    private void initWidgets() {
        getActionBar().setBackgroundDrawable(
                getResources().getDrawable(R.drawable.nav_bg));

        getActionBar().setDisplayShowHomeEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(false);

        signInFacebook = (Button) findViewById(R.id.login_fb);
        signInFacebook.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {

        case R.id.login_fb:
            intent = new Intent(this, ChangePassword.class);
            startActivity(intent);
            break;
        }
    }
}

希望它有用。

答案 2 :(得分:0)

对于具有搜索等所有功能的正确操作栏,您可以使用以下代码

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.search_action_provider);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }
    MenuItemCompat.setOnActionExpandListener(searchItem, new OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }
    });
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            if (adapter != null) {
                adapter.getFilter().filter(newText);
            }
            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            if (adapter != null) {
                adapter.getFilter().filter(query);
            }
            return true;
        }
    };
    searchView.setOnQueryTextListener(queryTextListener);
    return super.onCreateOptionsMenu(menu);
}

在serch.xml中,您可以

<?xml version="1.0" encoding="utf-8"?>

<item
    android:id="@+id/search_action_provider"
    android:icon="@drawable/abc_ic_search_api_holo_light"
    android:title="@string/abc_action_bar_home_description"
    yourapp:actionViewClass="android.support.v7.widget.SearchView"
    yourapp:showAsAction="ifRoom|collapseActionView"/>

相关问题