App一进来是空白页问题


解决Android启动显示空白界面的问题 . 

Android程序启动时,第一个看的界面并不是我们的指定的第一个Activity界面,而是显示了一个空白的界面,带标题栏的,但是界面什么内容都没有,这个界面只显示不到1秒左右的时间就会切换到我们的第一个Activity界面了,解决办法:在第一个启动的Activity的声明中增加:android:theme="@android:style/Theme.Translucent",具体代码如下(在清单文件中):

<activity
            android:name=".activity.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Translucent" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


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


转载来自:http://blog.163.com/love_wangchao/blog/static/21251930820141019103531803/

好的,下面是具体的步骤: 1. 在Android Studio中创建个新的项目。 2. 在res目录下创建个新的文件夹,命名为drawable,并将代表企业的图片放入该文件夹中。 3. 在res/layout目录下创建个新的布局文件,命名为activity_main.xml,用于显示企业的app封面。在该布局文件中添加个ImageView组件和个Button组件,如下所示: ```xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/logo" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/enterprise_logo" /> <Button android:id="@+id/start_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/logo" android:layout_centerHorizontal="true" android:text="开始使用" /> </RelativeLayout> ``` 4. 在res/layout目录下再创建个新的布局文件,命名为fragment_logo.xml,用于显示固定的Logo。在该布局文件中添加个ImageView组件,用于显示Logo,如下所示: ```xml <?xml version="1.0" encoding="utf-8"?> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/logo_image" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/logo" /> ``` 5. 在Java代码中创建个继承自Fragment的子类,命名为LogoFragment,并重写onCreateView方法,将fragment_logo.xml布局文件加载进来,并返回该View。 ```java public class LogoFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_logo, container, false); return view; } } ``` 6. 在MainActivity中,将LogoFragment添加到布局中。同时,为开始使用按钮添加点击事件,跳转至主页面(这里暂时使用空白页面)。 ```java public class MainActivity extends AppCompatActivity { private TextView mWelcomeText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 添加Logo Fragment FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); LogoFragment logoFragment = new LogoFragment(); fragmentTransaction.add(R.id.fragment_container, logoFragment); fragmentTransaction.commit(); // 添加开始使用按钮点击事件 Button startButton = findViewById(R.id.start_button); startButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 跳转至主页面 Intent intent = new Intent(MainActivity.this, HomeActivity.class); startActivity(intent); } }); // 显示欢迎信息 mWelcomeText = findViewById(R.id.welcome_text); String username = getIntent().getStringExtra("username"); mWelcomeText.setText("欢迎你," + username + "!"); } } ``` 7. 最后,在主页面(HomeActivity)中添加个EditText组件和个TextView组件,用于让用户输入用户名和密码,并在TextView中显示欢迎信息。 ```xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/username_edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:hint="请输入用户名" /> <EditText android:id="@+id/password_edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/username_edit" android:layout_marginTop="8dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:hint="请输入密码" android:inputType="textPassword" /> <Button android:id="@+id/login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/password_edit" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="登录" /> <TextView android:id="@+id/welcome_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/login_button" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:textColor="@android:color/black" /> </RelativeLayout> ``` 至此,个包含企业封面、固定Logo和用户登录功能的Android应用程序就完成了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值