導航:首頁 > 操作系統 > android數字選擇器

android數字選擇器

發布時間:2023-08-26 13:48:06

1. 求助一個android 文件選擇器的源碼(用於上傳文件時選擇並...

打開文件選擇器:
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);

try {
startActivityForResult( Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
}
}
選擇結果:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String path = FileUtils.getPath(this, uri);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
FileUtils文件

public class FileUtils {
public static String getPath(Context context, Uri uri) {

if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = { "_data" };
Cursor cursor = null;

try {
cursor = context.getContentResolver().query(uri, projection,null, null, null);
int column_index = cursor.getColumnIndexOrThrow("_data");
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
// Eat it
}
}

else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}

return null;
}
}

2. android怎麼給控制項添加選擇器

1 在/res/drawable/目錄下面新建一個xml文件,drawable就在res下面新建這個目錄

5 上面的步驟完成時棗攔,找到你的控制項所在的layout,設置其background屬性,如果上面selector叫button_press.xml,那麼其屬性就是android:background="@drawable/button_press"

閱讀全文

與android數字選擇器相關的資料

熱點內容
二手車搬運工app哪個好 瀏覽:477
怎麼編成一個mc伺服器 瀏覽:199
施工壓縮工期 瀏覽:552
python導入包代碼 瀏覽:60
武漢解壓體驗館創業 瀏覽:983
如何弄到一個伺服器 瀏覽:805
psp里的文件夾怎麼刪除 瀏覽:647
安卓手機如何在鎖屏的情況下拍攝視頻 瀏覽:459
安卓為什麼不能安裝procreate 瀏覽:529
如何修復王者榮耀的伺服器 瀏覽:654
javaif多個條件 瀏覽:506
顯示pdf縮略圖 瀏覽:533
奇跡移動命令圖片 瀏覽:857
多玩怎麼開到伺服器 瀏覽:656
基於單片機的水塔水位控制系統設計 瀏覽:480
yd什麼伺服器 瀏覽:520
muduo源碼分析 瀏覽:376
androidselector屬性 瀏覽:536
像素工廠如何加入伺服器 瀏覽:485
移動伺服器地址和埠號 瀏覽:656