主頁 > 移動端開發 > 【Android開發】小白入門必看的”四框“使用教程

【Android開發】小白入門必看的”四框“使用教程

2021-04-23 11:12:57 移動端開發

Android開發基礎入門、進階系列文章正陸續和大家發布分享,感興趣的小伙伴可以關注博主!一起探討和學習Android技術,助你在編程道路上一臂之力!

目錄

一、RadioButton單選框

二、CheckBox復選框

三、Spinner下拉框

四、ListView串列框

五、在xml檔案中為下拉框和串列框設定引數


Hello,你好呀,我是灰小猿,一個超會寫bug的程式猿!

最近在進行Android方向的學習,所以今天在這里和大家總結一下在Android開發中最經常使用的單選框、復選框、下拉框、串列框的詳細使用教程,

之后還會更新更多有關Android入門的技術供大家學習,所以歡迎小伙伴們關注我一起學習呀!

一、RadioButton單選框

單選框RadioButton的使用是建立在RadioGroup中的,原因是因為我們知道單選框的選擇是互斥的,也就是說只能選擇一個選項,那么如何做到單選框選項的互斥呢?

RadioGroup就起到了作用,在RadioGroup中的單選框選項RadioButton會自動形成互斥,以至于在其中的選項執行選擇一個,

判斷某個單選框是否被選中使用的是isChecked()方法,當該單選框被選中的時候回傳true,否則回傳false,

下面我們通過一個實際的案例來介紹單選框的具體使用,選擇性別并通過按鈕提交之后,在后臺可以獲取到選中的內容,并回傳前端界面訊息框顯示選中內容,

在XML檔案中建立一個單選框界面,進行性別的選擇,大家可以看一下其中的單選框RadioButton是放置在哪里的

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/title1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="單選框使用"
        android:textSize="30dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginTop="20dp"
        />

    <TextView
        android:id="@+id/title_sex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="性別:"
        android:textSize="30dp"
        app:layout_constraintTop_toBottomOf="@id/title1"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"

        />


    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@id/title_sex"
        app:layout_constraintBottom_toBottomOf="@id/title_sex"
        android:orientation="horizontal"
        android:layout_marginTop="30dp"

        >

        <RadioButton
            android:id="@+id/man"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30dp"
            android:text="男"
            />


        <RadioButton
            android:id="@+id/woman"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30dp"
            android:text="女"
            />


    </RadioGroup>

    <Button
        android:id="@+id/tijiao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="提交"
        android:textSize="30dp"
        android:layout_marginTop="30dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/title_sex"
        ></Button>

</androidx.constraintlayout.widget.ConstraintLayout>

獲取單選框選中內容的思路是:設定一個引數接收選中內容,之后判斷每一個單選框是否被選中,如果選中則將內容賦值給引數,

MainActivity.java檔案的代碼如下:

package com.example.radio_checkbox;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //獲取到三個控制元件的屬性
        Button bt1 = findViewById(R.id.tijiao);
        final RadioButton men = findViewById(R.id.man);
        final RadioButton women = findViewById(R.id.woman);

        //為提交按鈕添加事件監聽
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String sex = "";    //定義sex來接收單選框選擇的內容
                if (men.isChecked())sex="男";    //如果點擊了男
                else if (women.isChecked()) sex="女";    //如果點擊了女
                else sex="未選擇";     //如果未點擊

                //將選擇資訊在提示框輸出
                Toast.makeText(MainActivity.this,"性別是:" + sex,Toast.LENGTH_LONG).show();
            }
        });

    }
}

選中并提交后的效果如下:

二、CheckBox復選框

我們知道復選框的選項是可以被多個選中,那么很顯然,復選框的選項一定不是像單選框那樣存在互斥現象,因此復選框控制元件不需要放置在某一個容器中,而是直接設定即可,

判斷某個復選框是否被選中使用的是同樣也是isChecked()方法,當該復選框被選中的時候回傳true,否則回傳false,

下面我們通過一個實際的案例來介紹復選框的具體使用,選擇愛好并通過按鈕提交之后,在后臺可以獲取到選中的多個內容,并回傳前端界面訊息框顯示所有的選中內容,

在XML檔案中建立一個復選框界面,進行愛好的選擇,代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/title1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="復選框使用"
        android:textSize="30dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginTop="20dp"
        />


    <TextView
        android:id="@+id/title_aihao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="你的愛好:"
        android:textSize="30dp"
        app:layout_constraintTop_toBottomOf="@id/title1"
        app:layout_constraintLeft_toLeftOf="parent"

        android:layout_marginTop="30dp"
        />

    <CheckBox
        android:id="@+id/lanqiu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="籃球"
        android:textSize="30dp"
        app:layout_constraintTop_toBottomOf="@id/title_aihao"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        />


    <CheckBox

        android:id="@+id/paiqiu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="排球"
        android:textSize="30dp"
        app:layout_constraintTop_toBottomOf="@id/title_aihao"
        app:layout_constraintLeft_toRightOf="@id/lanqiu"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        />


    <CheckBox

        android:id="@+id/pingpangqiu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="乒乓球"
        android:textSize="30dp"
        app:layout_constraintTop_toBottomOf="@id/title_aihao"
        app:layout_constraintLeft_toRightOf="@id/paiqiu"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        />

    <Button
        android:id="@+id/tijiao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="提交"
        android:textSize="30dp"
        android:layout_marginTop="30dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/lanqiu"
        ></Button>

</androidx.constraintlayout.widget.ConstraintLayout>

獲取復選框選中內容的思路是:設定一個引數接收選中內容,之后判斷每一個復選框是否被選中,如果選中則將內容給增加給引數,最后所有的復選框都判斷完之后,引數中就存放了所有的選中項的文本,

MainActivity.java檔案的代碼如下:

package com.example.radio_checkbox;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //獲取到四個控制元件的屬性
        Button bt1 = findViewById(R.id.tijiao);
        final CheckBox laiqiu = findViewById(R.id.lanqiu);
        final CheckBox paiqiu = findViewById(R.id.paiqiu);
        final CheckBox pingpangqiu = findViewById(R.id.pingpangqiu);

        //為提交按鈕添加事件監聽
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String info = "";    //定義sex來接收單選框選擇的內容
                if (laiqiu.isChecked()) info += "籃球";    //如果點擊了籃球
                if (paiqiu.isChecked()) info += "排球";    //如果點擊了排球
                if (pingpangqiu.isChecked()) info += "乒乓球"; //如果點擊了乒乓球

                //將選擇資訊在提示框輸出
                Toast.makeText(MainActivity.this,"您的愛好是:" + info,Toast.LENGTH_LONG).show();
            }
        });

    }
}

選中并提交后的效果如下:

三、Spinner下拉框

Spinner下拉框的使用是需要建立Spinner控制元件的,那么肯定就會有小伙伴問了,Spinner中的選項如何添加,別急!與html中的下拉框添加文本的方式不同,Spinner下拉框的選擇文本是不在Spinner控制元件中寫入的,而是單獨的寫在陣列或一個xml檔案中,在這里先給大家介紹使用陣列存放Spinner下拉框的文本內容的方法,xml存放的方法待會介紹,

首先是先在xml界面中生成一個Spinner下拉框控制元件,

我們要實作的效果同樣是選中顯示的城市,然后通過按鈕提交之后,在后臺可以獲取到選中的內容,并回傳前端界面訊息框顯示選中的內容,

xml界面代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="請選擇你的城市:"
        android:textSize="20dp"
        ></TextView>


    <Spinner
        android:id="@+id/sp1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/text1"
        android:layout_marginTop="10dp"
        ></Spinner>

    <Button
        android:id="@+id/tijiao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="提交"
        android:textSize="20dp"
        app:layout_constraintTop_toBottomOf="@id/sp1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        ></Button>


</androidx.constraintlayout.widget.ConstraintLayout>

利用陣列設定Spinner下拉框內容的方法是:

  1. 建立一個string陣列,其中存放每一個選項,

  2. 將陣列添加到ArrayAdapter容器中,該ArrayAdapter的作用就是存放陣列元素

  3. 使用Spinner的setAdapter()方法將ArrayAdapter添加給下拉框,完成元素的添加

獲取下拉框選中內容的思路是:設定一個引數接收選中內容,使用Spinner的getSelectedItem().toString()方法獲取到選中內容賦值給引數,

MainActivity.java檔案的代碼如下:

package com.example.mylisttest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    String [] data = {"鄭州","深圳","北京"};    //串列框的選項

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//將選項加入到特定的容器中
        ArrayAdapter arrayAdapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1,data);


        //獲取到控制元件的屬性
        Button bt1 = findViewById(R.id.tijiao);
        final Spinner sp1 = (Spinner)findViewById(R.id.sp1);

        //將選項加入下拉框
        sp1.setAdapter(arrayAdapter);

        //為提交按鈕添加事件監聽
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String info = "";
                info = sp1.getSelectedItem().toString();

                //將選擇資訊在提示框輸出
                Toast.makeText(MainActivity.this,"您的城市是:" + info,Toast.LENGTH_LONG).show();
            }
        });



    }
}

選中并提交后的效果如下:

四、ListView串列框

ListView串列框的使用和設定其實和Spinner下拉框差不多,他們的選擇引數都是在控制元件之外設定的,同樣的ListView串列框的選擇引數也是單獨的寫在陣列或一個xml檔案中,不同的地方是ListView串列框只能點擊不能選中,所以我們需要單獨給ListView串列框設定監聽函式,

我們以設定ListView串列框,并在用戶點擊串列框某個選項時在界面訊息框中顯示該內容,

下面先在xml界面中實作ListView串列框:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="請選擇你的城市:"
        android:textSize="20dp"
        ></TextView>

   <ListView
       android:id="@+id/lv1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       app:layout_constraintTop_toBottomOf="@id/text1"
       android:layout_marginTop="30dp"
       ></ListView>


</androidx.constraintlayout.widget.ConstraintLayout>

監聽ListView串列框選中的方法是:為ListView串列框設定setOnItemClickListene()監聽方法,并使用其中的parent.getItemAtPosition(position)方法來獲取點擊的串列框,并獲取到文本,

MainActivity.java檔案的代碼如下:

package com.example.mylisttest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    String [] data = {"鄭州","深圳","北京"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ArrayAdapter arrayAdapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1,data);

        //獲取到串列框的屬性
        ListView lv1 = (ListView)findViewById(R.id.lv1);
        lv1.setAdapter(arrayAdapter);   //將陣列中存放的資訊添加到串列框中

//        為串列框增加監聽事件
        lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //獲取到串列框點擊的內容
                String strInfo = parent.getItemAtPosition(position).toString().trim();
                //將內容在訊息框輸出
                Toast.makeText(MainActivity.this,strInfo,Toast.LENGTH_LONG).show();
            }
        });



    }
}

選中并提交后的效果如下:

五、在xml檔案中為下拉框和串列框設定引數

在上面的方法中,我們已經介紹了使用陣列為下拉框和串列框設定引數,同樣我們也提到了使用xml檔案為下拉框和串列框設定引數,那么我們現在就來講一下,如何在xml檔案中為下拉框和串列框設定引數,這種方法也是之后經常使用的設定引數方法,

我們以下拉框為例進行設定,串列框方法一樣,使用該方法設定引數的優點就是省去了陣列元素需要添加到ArrayAdapter容器中繁瑣,并且方便之后在xml檔案中添加選擇項,首先我們應該在專案中res—>values檔案下建立一個xml檔案,我在這里命名為array.xml,

之后在xml檔案中寫入我們的要設定的選中引數:如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="array2">
        <item>煙臺</item>
        <item>鄭州</item>
        <item>青島</item>
        <item>上海</item>
    </string-array>


</resources>

添加完成后直接在下拉框的xml界面檔案中,找到設定下拉框的代碼,在其中添加android:entries屬性即可,界面代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="請選擇你的城市:"
        android:textSize="20dp"
        ></TextView>


    <Spinner
        android:id="@+id/sp1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/text1"
        android:layout_marginTop="10dp"
        android:entries="@array/array2"
        ></Spinner>

    <Button
        android:id="@+id/tijiao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="提交"
        android:textSize="20dp"
        app:layout_constraintTop_toBottomOf="@id/sp1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        ></Button>

</androidx.constraintlayout.widget.ConstraintLayout>

這樣在MainActivity.java檔案下就不需要設定陣列和對應的容器屬性,直接使用監聽即可,

MainActivity.java檔案的代碼如下:

package com.example.mylisttest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.List;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //獲取到控制元件的屬性
        Button bt1 = findViewById(R.id.tijiao);
        final Spinner sp1 = (Spinner)findViewById(R.id.sp1);

        //為提交按鈕添加事件監聽
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String info = "";
                info = sp1.getSelectedItem().toString();

                //將選擇資訊在提示框輸出
                Toast.makeText(MainActivity.this,"您的城市是:" + info,Toast.LENGTH_LONG).show();
            }
        });

    }
}

效果如下:

關于android中單選框、復選框、下拉框、串列框的使用就介紹完了,其中有不足的地方歡迎小伙伴評論指出!

之后還會繼續和大家分享更多Android入門及進階技術,感興趣的小伙伴可以關注我一起學習!

覺得有用記得點贊收藏加關注呀!

灰小猿陪你一起進步!

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/279292.html

標籤:其他

上一篇:Vue中使用proxy配置代理解決跨域問題

下一篇:C語言/C++ 檔案操作

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more