用As做QQ登录界面
时间: 2023-09-18 09:08:08 浏览: 58
首先,你需要在Android Studio中创建一个新项目,并在项目中添加QQ登录的SDK。
然后,在你的布局文件中,你可以使用以下代码来创建一个简单的QQ登录界面:
```
<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="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/qq_logo"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="QQ号"
android:layout_below="@id/logo"
android:layout_marginTop="50dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="密码"
android:inputType="textPassword"
android:layout_below="@id/username"
android:paddingLeft="16dp"
android:paddingRight="16dp"/>
<Button
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"
android:layout_below="@id/password"
android:layout_marginTop="50dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"/>
</RelativeLayout>
```
然后,在你的Activity中,你可以使用以下代码来处理登录按钮的点击事件:
```
public class LoginActivity extends AppCompatActivity {
private EditText mUsername;
private EditText mPassword;
private Button mLoginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mUsername = findViewById(R.id.username);
mPassword = findViewById(R.id.password);
mLoginButton = findViewById(R.id.login_button);
mLoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 在这里处理登录逻辑
String username = mUsername.getText().toString();
String password = mPassword.getText().toString();
// 调用QQ登录的SDK来进行登录
}
});
}
}
```
最后,记得在AndroidManifest.xml文件中添加QQ登录的权限和activity声明:
```
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencentYOUR_APP_ID" />
</intent-filter>
</activity>
```
其中,YOUR_APP_ID是你在QQ开放平台申请的应用ID。