1 2 3 4
| <EditText <!-- 设置密码框 --> android:password="true" </EditText>
|
1 2
| CheckBox cb; if (cb.isChecked()) { ... }
|
1 2
| ((EditText)findViewById(R.id.editText2)).getText().toString()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| b1=(Button)findViewById(R.id.button); b1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://www.uprogrammer.cn"));
startActivity(i); } });
|
1 2 3 4 5 6 7
| <intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="com.example.MyApplication.LAUNCH" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http" /> </intent-filter>
|
1 2 3 4 5 6 7 8 9 10
| <activity android:name="cn.uprogrammer.intentfilter.CustomActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="cn.uprogrammer.intentfilter.LAUNCH" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http" /> </intent-filter> </activity>
|
1 2 3 4 5 6 7 8 9 10 11 12
| public class CustomActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.custom_view); TextView label = (TextView) findViewById(R.id.show_data); Uri url = getIntent().getData(); label.setText(url.toString()); } }
|
文本框属性详解 http://www.runoob.com/w3cnote/android-tutorial-textview.html
1
| Drawable drawable = MainActivity.this.getResources().getDrawable(R.drawable.picture1);
|
1 2 3 4
| textView.setText(getString(R.string.section_format, 123));
<string name="section_format">Hello World %1$d</string>
|
1 2
| android:adjustViewBounds
|
1 2
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| private boolean mayRequestContacts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { return true; } if (shouldShowRequestPermissionRationale(READ_CONTACTS)) { Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(android.R.string.ok, new View.OnClickListener() { @Override @TargetApi(Build.VERSION_CODES.M) public void onClick(View v) { requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); } }); } else { requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); } return false; }
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == REQUEST_READ_CONTACTS) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { populateAutoComplete(); } } }
|
1 2 3 4 5 6 7 8 9
| String[] ctype = new String[]{"全部", "游戏", "电影", "娱乐", "图书"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ctype);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner spinner = super.findViewById(R.id.spinner); spinner.setAdapter(adapter);
|