小编Mar*_*ada的帖子

Webview Localhost Connection拒绝使用10.0.2.2地址

我只是在Android模拟器上制作一个基本的Webview应用程序,无法连接到我的计算机上托管的网站.

这是我的代码:

Android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emswebviewer"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
Run Code Online (Sandbox Code Playgroud)

主要活动Java文件:

public class MainActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        System.out.println("*** My thread is now configured to allow connection");
    }
    setContentView(R.layout.activity_main);

    webView = (WebView) findViewById(R.id.webView);
    webView.loadUrl("http://10.0.2.2:8080");
}
Run Code Online (Sandbox Code Playgroud)

终端(在本地主机端口8080上启动网站):

Michaels-MacBook-Pro-5:web michael$ php -S localhost:8080
PHP 5.5.14 Development Server started at Mon Dec 22 14:08:01 2014 …
Run Code Online (Sandbox Code Playgroud)

apache android localhost webview connection-refused

8
推荐指数
2
解决办法
2416
查看次数

使用MPAndroidChart的饼图对齐问题

在我的应用程序中使用饼图.使用以下库
api 'com.github.PhilJay:MPAndroidChart:v3.0.3'.

但我面临着对齐问题的问题.附上截图,请看一下:

graph_1 graph_2

码:

public static void chartDetails(PieChart mChart, Typeface tf) {
    mChart.animateXY(1400, 1400);
    mChart.getDescription().setEnabled(false);
    mChart.setCenterTextTypeface(tf);
    mChart.setCenterText("");
    mChart.setCenterTextSize(10f);
    mChart.setCenterTextTypeface(tf);
    // radius of the center hole in percent of maximum radius
    mChart.setHoleRadius(45f);
    mChart.setTransparentCircleRadius(50f);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    mChart.setTouchEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)

android mpandroidchart

7
推荐指数
2
解决办法
1658
查看次数

在Android 8 Oreo的WifiManager中,STARTcan方法没有收到任何响应

根据官方Android文档,WifiManager中的方法startScan在API级别P中已被弃用.但是我试图在API级别26(P之前)中使用此方法,但没有成功.如果用户同意所需的权限,我已经开发了一个需要扫描WiFi网络的应用程序,这种行为对于应用程序的适当运行至关重要.但是,在调用startScan方法时,我没有收到任何响应.¿任何人都可以帮我解决这个问题或找到替代解决方案吗?

这是文档的链接. https://developer.android.com/reference/android/net/wifi/WifiManager.html#startScan()

干杯

编辑:

这是启动de scannig进程的代码:

public boolean startScan() {
   WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
   if (!wm.isWifiEnabled()) {
     try {
       wm.setWifiEnabled(true);
     } catch (SecurityException e) {
       Log.w(LOG_TAG, "Error enabling wifi", e);
       return false;
     }
   }
   boolean started = wm.startScan();
   Log.d(LOG_TAG, "Scan started? " + started);
   return started;
}
Run Code Online (Sandbox Code Playgroud)

这是接收扫描结果的BroadcastReceiver.除了在带有targetSdkVersion 26+的Android 8中,它才有效

public class InOutWifiScanResultsReceiver extends BroadcastReceiver {
   private static final String LOG_TAG = "ScanResults";

   @Override
   public void onReceive(Context context, Intent intent) {
     super.onReceive(context, intent); // Never called in …
Run Code Online (Sandbox Code Playgroud)

android wifimanager android-8.0-oreo

5
推荐指数
1
解决办法
1014
查看次数

进度对话框 setContentView 在 onCreateDialog DialogFragment 中不起作用

我正在使用此代码Progressbar根据我的需要进行显示:

public class DelayedProgressDialog extends  DialogFragment
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
         setCancelable(false);
    }



    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
          ProgressDialog dialog = new ProgressDialog(getActivity());
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.setTitle(null);
        dialog.setContentView(R.layout._task);
        dialog.setIndeterminate(false);
        return dialog;
    }
}
Run Code Online (Sandbox Code Playgroud)

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     >

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="@dimen/_100sdp"
        android:layout_height="@dimen/_100sdp"
        android:id="@+id/progressBar"
        android:layout_centerInParent="true"
        android:indeterminateTint="@android:color/white"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

现在的问题是,当我调用这个时,我的自定义进度条没有显示在这个片段中:在没有标题的左侧显示正常进度条,我想在中间显示。如果我删除了 setContentview 然后没有得到任何效果,这意味着我的自定义视图没有显示在这个里面,我怎么能在这个里面显示我的视图。

android progressdialog android-progressbar android-dialogfragment

5
推荐指数
1
解决办法
920
查看次数

强制ExpandableListView fastScroll迭代所有项而不是部分

我正在使用a ExpandableListViewBaseExpandableListAdapter我注意到启用fastScroll滚动会遍历各个部分或标题.如果它不是因为它不能正常工作那将是伟大的.将fastScroll通过与在上面滚动的只有一小部分的所有部分进行迭代,刚开始滚动,然后在通过滚动的第一季度的时候,所有的部分滚动到屏幕上,滚动什么也不做.

这是一个演示gif:

示范GIF

我已经检查了这个老帖子android fastScroll只覆盖了列表的一部分,但是对我来说不起作用.

任何人都知道这个错误的另一个解决方法或知道如何强制ExpandableListView fastScroll迭代所有项目而不是部分?

这是示例代码,如果它对您有用.

activity_main.xml中

<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity">

  <ExpandableListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:fastScrollEnabled="true"
    android:layout_height="match_parent"></ExpandableListView>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java

public class MainActivity extends AppCompatActivity {

 private ExpandableListView listView;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   listView = findViewById(R.id.listview);

   ExpandableAdapter adapter = new ExpandableAdapter(this, getItems());
   listView.setAdapter(adapter);
 }

 private Map<String, List<String>> getItems() {
   Map<String, List<String>> items = new LinkedHashMap<>();
   // Loops to create stub items
   return items; …
Run Code Online (Sandbox Code Playgroud)

android expandablelistview expandablelistadapter fastscroll

5
推荐指数
0
解决办法
45
查看次数