还没到睡觉时间所以再加了一个界面...
问题:
1、下拉列表(因为还没看到这里...)
2、标题栏显示问题
3、按钮的 Enable 设置
..........
以下是代码:
布局 fragment_main(问题1)
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:focusable="true" 6 android:focusableInTouchMode="true" 7 android:background="#F7F7F9" 8 tools:context="com.dragon.android.qqregist.MainActivity$PlaceholderFragment" > 9 10 <Button 11 android:id="@+id/button2" 12 android:layout_width="wrap_content" 13 android:layout_height="50dp" 14 android:layout_alignParentTop="true" 15 android:background="#ffffff" 16 android:drawableLeft="@drawable/aa" 17 android:text="@string/button2" 18 android:textColor="#1CBAF5" /> 19 20 <TextView 21 android:id="@+id/textView2" 22 android:layout_width="match_parent" 23 android:layout_height="50dp" 24 android:layout_alignBaseline="@+id/button2" 25 android:layout_alignBottom="@+id/button2" 26 android:background="#ffffff" 27 android:gravity="center" 28 android:text="@string/pagename" 29 android:textColor="#1CBAF5" /> 30 31 <LinearLayout 32 android:id="@+id/linear" 33 android:layout_width="match_parent" 34 android:layout_height="wrap_content" 35 android:orientation="horizontal" 36 android:layout_below="@id/button2" 37 android:paddingTop="30dp" 38 android:paddingBottom="20dp" > 39 40 <Spinner 41 android:id="@+id/spinner1" 42 android:layout_width="0dp" 43 android:layout_height="wrap_content" 44 android:background="@drawable/bg_spinner" 45 android:layout_weight="1" 46 android:entries="@array/country"/> 47 48 <EditText 49 android:id="@+id/editText1" 50 android:layout_width="0dp" 51 android:layout_height="wrap_content" 52 android:layout_weight="2" 53 android:background="@drawable/bg_edittext" 54 android:ems="10" 55 android:inputType="phone" 56 android:hint="@string/innum" 57 android:color="#000000" 58 android:textSize="15sp" > 59 60 </EditText> 61 62 </LinearLayout> 63 64 <Button 65 android:id="@+id/button1" 66 android:layout_width="match_parent" 67 android:layout_height="wrap_content" 68 android:layout_marginLeft="10dp" 69 android:layout_marginRight="10dp" 70 android:layout_below="@id/linear" 71 android:enabled="false" 72 android:background="@drawable/bg_button" 73 android:text="@string/button" 74 android:gravity="center" 75 android:textColor="#FFFFFF" /> 76 77 <CheckBox 78 android:id="@+id/checkBox1" 79 android:layout_width="wrap_content" 80 android:layout_height="wrap_content" 81 android:layout_marginTop="10dp" 82 android:layout_marginLeft="10dp" 83 android:layout_below="@id/button1" 84 android:text="@string/sure" 85 android:textSize="12sp" 86 android:textColor="#A6A6A7" /> 87 88 <TextView 89 android:id="@+id/textView1" 90 android:layout_width="wrap_content" 91 android:layout_height="wrap_content" 92 android:layout_alignBaseline="@+id/checkBox1" 93 android:layout_alignBottom="@+id/checkBox1" 94 android:layout_marginLeft="10dp" 95 android:layout_toRightOf="@+id/checkBox1" 96 android:autoLink="all" 97 android:text="@string/protocol" 98 android:textSize="12sp" /> 99 100 </RelativeLayout>
fragment_main
EditText、Spinner 以及 Button 修改前后的背景
1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" > 3 4 <stroke android:width="1px" android:color="#BEBEBE"/> 5 6 <solid android:color="#FFFFFF" /> 7 8 <padding 9 android:left="10dp" 10 android:top="10dp" 11 android:bottom="10dp"/> 12 13 </shape>
bg_edittext
1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" > 3 4 <stroke android:width="1px" android:color="#BEBEBE"/> 5 6 <solid android:color="#FFFFFF" /> 7 8 <padding 9 android:left="10dp" 10 android:top="10dp" 11 android:bottom="10dp"/> 12 13 </shape>
bg_spinner
1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" > 3 4 <solid android:color="#808080"/> 5 6 <corners android:radius="10dp"/> 7 8 <padding 9 android:top="10dp" 10 android:bottom="10dp"/> 11 12 </shape>
bg_button
1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" > 3 4 <solid android:color="#1CBAF5"/> 5 6 <corners android:radius="10dp"/> 7 8 <padding 9 android:top="10dp" 10 android:bottom="10dp"/> 11 12 </shape>
bg_buttin_change
Spinner 的下拉数据 arrays
1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 <string-array name="country"> 4 <item >中国 +86</item> 5 <item >香港 +852</item> 6 <item >澳门 +853</item> 7 <item >台湾 +886</item> 8 <item >日本 +81</item> 9 <item >美国 +1</item> 10 <item >英国 +44</item> 11 </string-array> 12 </resources>
arrays
标题栏的背景(问题2 -- 放弃)
1 <?xml version="1.0" encoding="utf-8"?> 2 <resources xmlns:android="http://schemas.android.com/apk/res/android"> 3 4 <style name="bg_title" parent="android:Theme"> 5 <item name="android:windowTitleBackgroundStyle">@style/Titleground</item> 6 <item name="android:windowTitleStyle">@style/windowTitleStyle</item> 7 <item name="android:windowTitleSize">40dp</item> 8 </style> 9 10 <style name="Titleground"> 11 <item name="android:background">#FFFFFF</item> 12 </style> 13 14 <style name="windowTitleStyle"> 15 <item name="android:text">@string/pagename</item> 16 <item name="android:textColor">#1CBAF5</item> 17 <item name="android:paddingTop">2dp</item> 18 <item name="android:paddingBottom">2dp</item> 19 <item name="android:textSize">20sp</item> 20 </style> 21 22 </resources>
bg_titile
问题2替换方法:隐藏标题栏 -- 在 AndroidManifest 中添加 -- android:theme="@android:style/Theme.NoTitleBar" >
MainActivity (问题3)
1 package com.dragon.android.qqregist; 2 3 import android.annotation.SuppressLint; 4 import android.app.Activity; 5 import android.graphics.Color; 6 import android.os.Bundle; 7 import android.view.View; 8 import android.widget.AdapterView; 9 import android.widget.AdapterView.OnItemSelectedListener; 10 import android.widget.Button; 11 import android.widget.CheckBox; 12 import android.widget.CompoundButton; 13 import android.widget.CompoundButton.OnCheckedChangeListener; 14 import android.widget.EditText; 15 import android.widget.Spinner; 16 import android.widget.Toast; 17 18 public class MainActivity extends Activity { 19 private Spinner spinner = null; 20 private EditText editText1; 21 private Button button2; 22 private Button button1; 23 private CheckBox checkBox1; 24 25 @Override 26 protected void onCreate(Bundle savedInstanceState) { 27 super.onCreate(savedInstanceState); 28 setContentView(R.layout.fragment_main); 29 30 spinner = (Spinner) findViewById(R.id.spinner1); 31 spinner.setSelection(0); 32 editText1 = (EditText) findViewById(R.id.editText1); 33 editText1.setHintTextColor(Color.GRAY); 34 button2 = (Button) findViewById(R.id.button2); 35 // 设置空间置顶 36 button2.bringToFront(); 37 button1 = (Button) findViewById(R.id.button1); 38 39 // spinner 选择监听事件 40 spinner.setOnItemSelectedListener(new OnItemSelectedListener() { 41 42 @Override 43 // parent当前spinner pos/id选中的值所在位置/行 44 public void onItemSelected(AdapterView<?> parent, View view, 45 int pos, long id) { 46 // 得到string-array 47 String[] country = getResources().getStringArray( 48 R.array.country); 49 Toast.makeText(MainActivity.this, "你选择的是:" + country[pos], 50 Toast.LENGTH_SHORT).show(); 51 } 52 53 @Override 54 public void onNothingSelected(AdapterView<?> parent) { 55 // Another interface callback 56 } 57 }); 58 checkBox1 = (CheckBox) findViewById(R.id.checkBox1); 59 checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() { 60 61 @Override 62 @SuppressLint("NewApi") 63 public void onCheckedChanged(CompoundButton view, boolean inChecked) { 64 button1.setEnabled(inChecked); 65 if (!inChecked) { 66 // 设置按钮的背景 67 button1.setBackground(getResources().getDrawable( 68 R.drawable.bg_button)); 69 } else { 70 button1.setBackground(getResources().getDrawable( 71 R.drawable.bg_button_change)); 72 } 73 } 74 }); 75 } 76 }
图片素材
aa.png -- ps用不了了,改不了颜色...
---------------------改是时候睡觉了...---------------------
时间: 2024-10-21 09:39:14