这是我登录页面按钮的XML布局代码:
<Button
android:id="@+id/googleLogin"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/logoImage"
android:layout_alignParentBottom="true"
android:layout_marginBottom="54dp"
android:background="#d34836"
android:text="@string/google_login"
android:textColor="#ffffff"
android:drawableStart="@drawable/post_gplus"
android:paddingLeft="12sp"
android:paddingRight="12sp"
android:drawablePadding="5sp"
android:onClick="clickLoginGoogle"/>
<Button
android:id="@+id/facebookLogin"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/googleLogin"
android:layout_alignBottom="@+id/googleLogin"
android:layout_marginStart="19dp"
android:layout_toEndOf="@+id/googleLogin"
android:background="#4267b2"
android:drawableLeft="@drawable/post_facebook"
android:text="@string/facebook_login"
android:textColor="#ffffff"
android:paddingLeft="12sp"
android:paddingRight="12sp"
android:drawablePadding="5sp"
android:onClick="clickLoginFacebook"/>
这是我登录页面的java代码:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import android.content.Intent;
public class LoginScreen extends AppCompatActivity {
public void clickLoginFacebook(View view1)
{
toastMsg(" Logged in through Facebook!!");
Intent intent = new Intent(LoginScreen.this,UserDetail.class);
startActivity(intent);
}
public void clickLoginGoogle(View view1)
{
toastMsg(" Logged in through Google");
Intent intent = new Intent(LoginScreen.this,UserDetail.class);
startActivity(intent);
}
public void toastMsg(String msg) {
Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
toast.show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_screen);
}
}
这是我要转换到的屏幕的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.blahblah.testapp.UserDetail">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="74dp"
android:textColor="#616161"
android:textSize="16sp"
tools:text="Name:"
android:id="@+id/textView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="113dp"
android:textColor="#616161"
android:textSize="16sp"
tools:text="Email:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="152dp"
android:textSize="16sp"
android:textColor="#616161"
tools:text="Age:"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="191dp"
android:textSize="16sp"
android:textColor="#616161"
tools:text="Gender:"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="230dp"
android:textSize="16sp"
android:textColor="#616161"
tools:text="Location:"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="269dp"
android:textSize="16sp"
android:textColor="#616161"
tools:text="Optional"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="308dp"
android:textSize="16sp"
android:textColor="#616161"
tools:text="Date of Birth:"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="330dp"
android:textSize="14sp"
android:textColor="#9e9e9e"
tools:text="(Get special offers on your birthday)"
/>
</RelativeLayout>
这是我的清单代码:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".LoginScreen"
android:theme="@style/Theme.AppCompat.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".UserDetail"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:label="UserDetail" >
</activity>
</application>
登录页面的名称是LoginScreen,我要转换的页面名称是UserDetail
当我按下按钮时,我得到的是一个黑色的空白屏幕而不是我正在设计的用户界面页面。有人能告诉我这是什么问题吗?
当我点击按钮时,这是我的logcat日志:
12-13 20:08:25.236 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
12-13 20:08:25.245 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
12-13 20:08:25.281 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
12-13 20:08:25.345 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
12-13 20:08:25.396 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
12-13 20:08:25.411 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
12-13 20:08:25.509 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
12-13 20:08:39.174 2423-2443/io.blahblah.testapp D/EGL_emulation: eglMakeCurrent: 0xb429dac0: ver 2 0
转换的登录屏幕
的屏幕
时的屏幕
答案 0 :(得分:0)
如果这不起作用
替代 - :
Button facebook=(Button)findViewById(R.id.facebookLogin);
facebook.setOnClickListener(new View.OnClickListener)
{
Do watever you want
});
}
答案 1 :(得分:0)
提供清单中活动类的完整路径。
例如:假设您的活动位于src下的app包内,请在XML中使用如下所示的路径
id title cover
-----------------------
1 title 4.jpg
2 title 6.jpg
希望这可以解决您的问题。
答案 2 :(得分:0)
请使用android:text
代替tools:text
tools:text
:这仅用于布局预览以查看设计,在运行应用程序时不会显示。
android:text
:运行应用程序时将显示该文本。
希望它有所帮助!