android-UI design(first app)
2015-12-27 20:11
393 查看
The graphical user interface for an Android app is built using a hierarchy of
are usually UI widgets such as buttons or text
fields.
are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.
Layouts are subclasses of the
In this exercise, you'll work with a
> Run Your App: adb
install -r app/build/outputs/apk/app-debug.apk
>
Note: If you
are using an IDE other than Android Studio, your project does not contain the
That's OK because you will update this method later and won't be using that layout.
>In your manifest file,
within the
for your
The system uses this value to implement default navigation behaviors, such as Up
navigationon Android 4.1 (API level 16) and higher. You can provide the same navigation behaviors for older versions of Android by using the Support
Library and adding the
as shown here.
> The complete
for
Viewand
ViewGroupobjects.
Viewobjects
are usually UI widgets such as buttons or text
fields.
ViewGroupobjects
are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.
Layouts are subclasses of the
ViewGroup.
In this exercise, you'll work with a
LinearLayout.
> Run Your App: adb
install -r app/build/outputs/apk/app-debug.apk
/** Called when the user clicks the Send button */ public void sendMessage(View view) { Intent intent = new Intent(this, DisplayMessageActivity.class); EditText editText = (EditText) findViewById(R.id.edit_message); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); }
>
public class DisplayMessageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); } } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle app bar item clicks here. The app bar // automatically handles 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); } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_display_message, container, false); return rootView; } } }
Note: If you
are using an IDE other than Android Studio, your project does not contain the
activity_display_messagelayout that's requested by
setContentView().
That's OK because you will update this method later and won't be using that layout.
>In your manifest file,
AndroidManifest.xml,
within the
Applicationelement, add the
<activity>element
for your
DisplayMessageActivityclass, as follows:
<application ... > ... <activity android:name="com.mycompany.myfirstapp.DisplayMessageActivity" android:label="@string/title_activity_display_message" android:parentActivityName="com.mycompany.myfirstapp.MyActivity" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.mycompany.myfirstapp.MyActivity" /> </activity> </application>
The system uses this value to implement default navigation behaviors, such as Up
navigationon Android 4.1 (API level 16) and higher. You can provide the same navigation behaviors for older versions of Android by using the Support
Library and adding the
<meta-data>element
as shown here.
> The complete
onCreate()method
for
DisplayMessageActivitynow looks like this:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null) .show(); } }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); Intent intent = getIntent(); String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE); TextView textView = new TextView(this); textView.setTextSize(40); textView.setText(message); RelativeLayout layout = (RelativeLayout) findViewById(R.id.content); layout.addView(textView);
相关文章推荐
- startActivityForResult无法调用singleTask的Activity返回的数据
- Ubuntu 14.04.2 移植FFmpeg 2.8.3 到Android平台
- C#-MVC开发微信应用(3)--文本消息和图文消息的应答
- Android Tag-start Training
- 01.cocos2d-x制作弹出层(Layer)
- 一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
- Application Icons and Images for iOS
- Windows下搭建Android NDK开发环境及命令行编译
- Android设计模式之一个例子让你彻底明白装饰者模式(Decorator Pattern)
- Android内核学习笔记
- Objective-C与JavaScript的简易交互操作
- 从Unity引擎过度到Unreal4引擎(最终版)
- iOS- 极光推送
- iOS --- 多线程之NSOperation
- Android应用打开另一个应用程序
- android 双缓冲分析一些基本的原理
- 安卓开发全屏实现方法
- ios对于字符串的url编码和解码问题
- android sdk manager的国内代理
- Android Studio安装及配置