android 自动创建ap,Android连载10-动态添加页面、创建一个新闻app

Android连载10-动态添加页面、创建一个新闻app

一、动态规划界面的大小

1.我们在res的文件夹里面创建一个新的文件夹large_fragment用来,然后写一个界面,activity_main.xml文件,用于存储平板电脑等一些分辨率高的界面。也就是说小屏幕使用正常activity_main文件、大屏幕就使用large_fragment文件夹里面的界面。

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:id="@+id/left_fragment"

android:name="com.example.fragmenttest.LeftFragment"

android:layout_height="match_parent"

android:layout_width="match_parent" />

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

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:name="com.example.fragmenttest.LeftFragment"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" />

android:name="com.example.fragmenttest.RightFragment"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="3" />

LinearLayout>

54bc29b31c4d65f9916613d02ab0b0cd.png

二、精准选择界面

1.我们在res下面建一个文件夹layout-sw600dp,这个就意味着如果屏幕的宽度小于600dp的时候,则会默认加载这个文件夹下面的activity_main界面。

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

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:name="com.example.fragment.LeftFragment"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" />

android:name="com.example,fragmenttest.RightFragment"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="3" />

LinearLayout>

三、我们在编写app的时候总不能需要维护两套代码,但是我们接下来将会探究如果能够编写一个同时兼容电脑和手机的app。

我们建立一个新闻的app,下面先写一个新闻类,具体的细节我们下次在写。

package com.example.fragmentbestpractice;public class News {

private String title;

private String content;  public String getTitle() {    return title;

}  public void setTitle(String title) {    this.title = title;

}  public String getContent() {    return content;

}  public void setContent(String content) {    this.content = content;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android设备上创建WiFi热点需要使用`WifiManager`和`ConnectivityManager`类。以下是创建WiFi热点的代码示例: ``` WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(false); ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Method method = connectivityManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); WifiConfiguration wifiConfiguration = new WifiConfiguration(); wifiConfiguration.SSID = "MyWiFiHotspot"; // 热点名称 wifiConfiguration.preSharedKey = "password"; // 热点密码 wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); method.invoke(connectivityManager, wifiConfiguration, true); ``` 其中,`WifiManager`用于关闭设备的WiFi,因为设备只能作为热点或连接到WiFi网络,不能同时进行。`ConnectivityManager`用于开启热点,通过反射调用`setWifiApEnabled()`方法实现。 在`WifiConfiguration`对象中定义热点名称和密码,并设置热点管理类型为WPA_PSK。最后,调用`method.invoke()`方法开启热点。 需要注意的是,Android 6.0及以上版本的设备需要在运行时请求`android.permission.ACCESS_COARSE_LOCATION`权限才能开启热点。可以使用以下代码请求权限: ``` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_CODE_LOCATION_PERMISSION); } ``` 其中,`REQUEST_CODE_LOCATION_PERMISSION`是自定义的权限请求代码,用于在`onRequestPermissionsResult()`方法中处理请求结果。 希望这个代码示例能帮助到你创建Android设备上的WiFi热点。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值