中的这个截图来总结:
此处会在AndroidManifest.xml中新增对应的activity配置:
1
2
3
4
5
6
7
8
|
< activity android:name = "crifan.com.downloadsongtastemusic.DirectoryBrowser" android:label = "@string/title_activity_directory_browser" android:parentActivityName = "com.crifan.DownloadSongtaste.MainActivity" > < meta-data android:name = "android.support.PARENT_ACTIVITY" android:value = "com.crifan.DownloadSongtaste.MainActivity" /> </ activity > |
对应的效果:
增加了一些默认的字符串和标题值:
1
2
|
< string name = "hello_world" >Hello world!</ string > < string name = "title_activity_directory_browser" >Directory Browser</ string > |
效果:
对应的,添加了menu下面的xml配置文件,用于表示菜单配置方面的内容:
1
2
3
4
5
6
7
8
9
|
< item android:id = "@+id/menu_settings" android:orderInCategory = "100" android:showAsAction = "never" android:title = "@string/menu_settings" /> </ menu > |
效果:
对应的layout布局中,必须也要生成对应的配置。
我此处,是另外,借用了别人的配置,如下:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<!-- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".DirectoryBrowser" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" /> </RelativeLayout> --> < LinearLayout android:layout_width = "250dp" android:layout_height = "400dp" android:orientation = "vertical" > < TextView android:id = "@+id/mPath" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:padding = "5dp" android:textSize = "18sp" > </ TextView > < ListView android:id = "@android:id/list" android:layout_width = "fill_parent" android:layout_height = "330dp" > </ ListView > < LinearLayout android:gravity = "center" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:orientation = "horizontal" > < Button android:id = "@+id/buttonConfirm" android:layout_width = "125dp" android:layout_height = "fill_parent" android:text = "OK" /> < Button android:id = "@+id/buttonCancle" android:layout_width = "125dp" android:layout_height = "fill_parent" android:text = "Cancel" /> </ LinearLayout > </ LinearLayout > |
效果是:
在对应的,domain下,新增了对应的此java函数,用于实现,对应的所有的逻辑,默认是:
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
33
34
35
36
37
38
39
40
41
42
43
|
package crifan.com.downloadsongtastemusic; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.MenuItem; import android.support.v4.app.NavUtils; public class DirectoryBrowser extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_directory_browser); // Show the Up button in the action bar. getActionBar().setDisplayHomeAsUpEnabled( true ); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_directory_browser, menu); return true ; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // NavUtils.navigateUpFromSameTask( this ); return true ; } return super .onOptionsItemSelected(item); } } |
之所以是放在
/src/crifan/com/downloadsongtastemusic/
下面,那是因为之前自己新建activity时,设置的parent是
crifan.com.DownloadSongtasteMusic
暂时不太清楚这个是啥东东。
不过,也找到了对应的位置,是在libs下面的:
在当前界面中,实现对应的Indent,表示要实现的是界面切换:
在我此处的src/crifan/com/downloadsongtastemusic/MainActivity.java中某个函数中实现了:
1
2
3
4
5
6
|
/** Choose folder for downloaded music file to save */ public void ChooseFoler(View view) { Intent intent = new Intent(MainActivity. this , DirectoryBrowser. class ); startActivityForResult(intent, FOLDER_RESULT_CODE); } |
注:
1. 其中此处用的是startActivityForResult,表示的是,启动一个Indent,(同时是要等新界面中返回来结果的)
所以,此处才需要另外再实现,获得了返回的结果后的处理:
1
2
3
4
5
6
7
8
9
10
|
@Override protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (FOLDER_RESULT_CODE == requestCode){ Bundle bundle = null ; if (data!= null &&(bundle=data.getExtras())!= null ){ EditText etSaveTo = (EditText) findViewById(R.id.saveTo); etSaveTo.setText(bundle.getString( "file" )); } } } |
2.如果你无需获得返回值,那么只需要使用startActivity:
1
|
startActivity(intent); |
就是在对应的onCreate中,做自己需要做的初始化的事情。
默认是的:
1
2
3
4
5
|
super .onCreate(savedInstanceState); setContentView(R.layout.activity_directory_browser); // Show the Up button in the action bar. getActionBar().setDisplayHomeAsUpEnabled( true ); } |
此处,可以根据自己需要,改为自己要的功能。比如此处文件夹浏览,就是,借鉴了别人的代码,写成类似于:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package crifan.com.downloadsongtastemusic; import java.io.File; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.support.v4.app.NavUtils; //import android.app.Activity; import android.app.ListActivity; public class DirectoryBrowser extends ListActivity { //public class DirectoryBrowser extends Activity { private List<String> items = null ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_directory_browser); // Show the Up button in the action bar. //getActionBar().setDisplayHomeAsUpEnabled(true); getFiles( new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" ).listFiles()); } private void getFiles(File[] files){ items = new ArrayList<String>(); items.add(getString(R.string.goto_root)); for (File file : files){ items.add(file.getPath()); } ArrayAdapter<String> fileList = new ArrayAdapter<String>( this ,R.layout.file_list_row, items); setListAdapter(fileList); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_directory_browser, menu); return true ; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // NavUtils.navigateUpFromSameTask( this ); return true ; } return super .onOptionsItemSelected(item); } } |
关于本站 | 网站地图 | 手机版 | XML地图 | 反馈 | 版权申明 皖ICP备13006370号-1