最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

項(xiàng)目: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 {
/*
  = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  本實(shí)例主要學(xué)習(xí),屏幕翻轉(zhuǎn)時(shí),界面如何自適應(yīng),創(chuàng)建橫屏布局
  1.禁止切換橫屏:在 AndroidManifest.xml-->application->activity->中設(shè)置如下代碼(android:screenOrientation="portrait")
   <activity android:name=".MainActivity" android:screenOrientation="portrait" >
  2. 創(chuàng)建 Landscape 布局,橫屏?xí)r,會(huì)自動(dòng)加載 Landscape 的布局界面(清單文件中,注意去掉 android:screenOrientation="portrait" )
  3. 翻轉(zhuǎn)屏幕時(shí),保存窗口控件的狀態(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中的值不為空,如果有相應(yīng)的這個(gè)組件的值,則讀取出來賦值上去
    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());
  }
}

擴(kuò)展學(xué)習(xí):

UI界面設(shè)計(jì)

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",可選擇的選項(xiàng)還有top、bottom、left、right、center等,center相當(dāng)于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上面的文字默認(rèn)英文全部大寫,可以通過設(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)知識(shí)點(diǎn)如果還有什么疏漏大家可以直接聯(lián)系小編,感謝你的閱讀和對腳本之家的支持。

相關(guān)文章

最新評論

台中县| 旺苍县| 富裕县| 隆化县| 望城县| 甘德县| 辽宁省| 清水县| 武夷山市| 那曲县| 柳河县| 曲阜市| 吉木萨尔县| 贞丰县| 五峰| 汽车| 吐鲁番市| 南陵县| 龙州县| 织金县| 威信县| 宣汉县| 叙永县| 尉氏县| 青田县| 开化县| 安国市| 卓尼县| 万源市| 绥宁县| 公主岭市| 长治市| 凯里市| 密云县| 凌云县| 博爱县| 洮南市| 田阳县| 麻城市| 镇宁| 桑日县|