安卓app_sl3_25同意游戏条款功能示范
安卓app_sl3_25同意游戏条款功能示范
package com.example.sl3_25; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageButton; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ImageButton imageButton=(ImageButton)findViewById(R.id.start); CheckBox checkbox=(CheckBox)findViewById(R.id.checkBox1); checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO 自动生成的方法存根 if(isChecked) { imageButton.setVisibility(View.VISIBLE); } else { imageButton.setVisibility(View.INVISIBLE); } imageButton.invalidate();//重绘ImageButton } }); imageButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO 自动生成的方法存根 Toast.makeText(MainActivity.this, "进入游戏。。。", Toast.LENGTH_SHORT).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <!-- activity_main.xml --> xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/background" android:gravity="center" tools:context="com.example.sl3_25.MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="20dp" style="@style/artclestyle" android:text="@string/artcle" /> <CheckBox android:id="@+id/checkBox1" android:textSize="22dp" android:button="@drawable/check_box" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我同意" /> <ImageButton android:id="@+id/start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="invisible" android:src="@drawable/button_state" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!--  表示空格,string.xml -->
<resources>
<string name="app_name">sl3_25同意游戏条款</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="artcle">         温馨提示:本游戏适合各年龄段的玩家,请您合理安排游戏时间,不要沉迷游戏!
当您连续在线2小时间后,系统将自动结束游戏。如果同意该条款请勾选“我同意”复选框,方可进入游戏。</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<!-- button_state.xml -->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/start_b"/>
<item android:state_pressed="false" android:drawable="@drawable/start_a"/>
</selector>
<?xml version="1.0" encoding="utf-8"?> <!-- check_box.xml --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false" android:drawable="@drawable/check_f"/> <item android:state_checked="true" android:drawable="@drawable/check_t"/> </selector>
<resources> <!-- style.xml --> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <style name="artclestyle"> <item name="android:textSize">20px</item> <item name="android:textColor">#ff6600</item> </style> </resources>
欢迎讨论,相互学习。
cdtxw@foxmail.com