欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android Studio屏幕方向以及UI界面狀態(tài)的保存代碼詳解

 更新時間:2019年10月31日 16:03:20   作者:孤峰皓月  
在本篇文章里小編給各位整理的是關(guān)于Android Studio屏幕方向以及UI界面狀態(tài)的保存代碼以及相關(guān)知識點,需要的跟著學習下。

項目:Orientation

package com.example.orientation;
 
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
 
import androidx.appcompat.app.AppCompatActivity;
 
public class MainActivity extends AppCompatActivity {
/*
  = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  本實例主要學習,屏幕翻轉(zhuǎn)時,界面如何自適應,創(chuàng)建橫屏布局
  1.禁止切換橫屏:在 AndroidManifest.xml-->application->activity->中設(shè)置如下代碼(android:screenOrientation="portrait")
   <activity android:name=".MainActivity" android:screenOrientation="portrait" >
  2. 創(chuàng)建 Landscape 布局,橫屏時,會自動加載 Landscape 的布局界面(清單文件中,注意去掉 android:screenOrientation="portrait" )
  3. 翻轉(zhuǎn)屏幕時,保存窗口控件的狀態(tài)值;
 
  = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
 */
  Button button;
  TextView textView;
 
  String TAG = "myTag";
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 
    button = findViewById(R.id.button );
    textView = findViewById(R.id.textView);
 
    //如果State中的值不為空,如果有相應的這個組件的值,則讀取出來賦值上去
    if(savedInstanceState !=null)
    {
      String s = savedInstanceState.getString("key");
      textView.setText(s);
    }
 
    button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        textView.setText(button.getText());
      }
    });
  }
 
  @Override
  protected void onDestroy() {
    super.onDestroy();
    Log.d(TAG,"onDestroy:");
  }
 
  @Override
  //將 textView 中的值,先保存到 outState 中(鍵值對)
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("key",textView.getText().toString());
  }
}

擴展學習:

UI界面設(shè)計

TextView

<TextView
    android:id="@+id/textview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="This is a TextView"
    android:textColor="#00ff00"
    android:textSize="24sp" />

要想使得文字居中,需要添加屬性android:gravity="center",可選擇的選項還有top、bottom、left、right、center等,center相當于center_vertical|center_horizontal。
使用android:textSize="24sp"指定文字大小,android:textColor="#00ff00"指定文字顏色。

Button

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button"
    android:textAllCaps="false"/>

在Android中,Button上面的文字默認英文全部大寫,可以通過設(shè)置android:textAllCaps="false"改變

EditText

<EditText
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="HelloWorld"
    android:maxLength="20"
    android:maxLines="1" />

通過設(shè)置hint屬性可以得到提示文字,設(shè)置maxLines使得輸入框中最大輸入行數(shù)。

以上相關(guān)知識點如果還有什么疏漏大家可以直接聯(lián)系小編,感謝你的閱讀和對腳本之家的支持。

相關(guān)文章

  • Android自定義View實現(xiàn)直播點贊特效

    Android自定義View實現(xiàn)直播點贊特效

    這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)直播點贊特效,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Android實現(xiàn)系統(tǒng)日歷同步日程

    Android實現(xiàn)系統(tǒng)日歷同步日程

    這篇文章主要為大家詳細介紹了Android實現(xiàn)系統(tǒng)日歷同步日程,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Android應用的LinearLayout中嵌套RelativeLayout的布局用法

    Android應用的LinearLayout中嵌套RelativeLayout的布局用法

    這篇文章主要介紹了Android應用的LinearLayout中嵌套RelativeLayout的布局用法,文后還給出了線性布局中一些組件位置的調(diào)試經(jīng)驗,需要的朋友可以參考下
    2016-04-04
  • 使用UITextField限制輸入金額是正確小數(shù)

    使用UITextField限制輸入金額是正確小數(shù)

    通過我們使用正則表達式和textfield的方法判斷輸入金額是否為正確的金額,今天小編給大家使用UITextField限制輸入金額是正確小數(shù),有需要的朋友可以參考下
    2016-05-05
  • Android ViewModel的作用深入講解

    Android ViewModel的作用深入講解

    這篇文章主要介紹了Android ViewModel的作用,ViewModel類旨在以注重生命周期的方式存儲和管理界面相關(guān)數(shù)據(jù),ViewModel類讓數(shù)據(jù)可在發(fā)生屏幕旋轉(zhuǎn)等配置更改后繼續(xù)留存,需要詳細了解可以參考下文
    2023-05-05
  • Golang+Android基于HttpURLConnection實現(xiàn)的文件上傳功能示例

    Golang+Android基于HttpURLConnection實現(xiàn)的文件上傳功能示例

    這篇文章主要介紹了Golang+Android基于HttpURLConnection實現(xiàn)的文件上傳功能,結(jié)合具體實例形式分析了Android基于HttpURLConnection的客戶端結(jié)合Go語言服務(wù)器端實現(xiàn)文件上傳功能的操作技巧,需要的朋友可以參考下
    2017-03-03
  • Android對話框AlertDialog與DatePickerDialog及TimePickerDialog使用詳解

    Android對話框AlertDialog與DatePickerDialog及TimePickerDialog使用詳解

    這篇文章主要介紹了Android對話框中的提醒對話框AlertDialog、日期對話框DatePickerDialog、時間對話框TimePickerDialog使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2022-09-09
  • Android文件操作工具類詳解

    Android文件操作工具類詳解

    這篇文章主要為大家詳細介紹了Android文件操作工具類,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Android studio將Module打包成Jar的方法

    Android studio將Module打包成Jar的方法

    這篇文章主要介紹了Android studio將Module打包成Jar的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-10-10
  • 使用RxJava中遇到的一些”坑“

    使用RxJava中遇到的一些”坑“

    這篇文章主要給大家介紹了在使用RxJava中可能遇到的一些”坑“,文中總結(jié)的這些坑都是我在實踐中遇到的,現(xiàn)在分享出來給大家,希望大家能夠避免這個問題,需要的朋友們下面來一起看看吧。
    2017-05-05

最新評論