将 ActivityGroup 应用程序转换为使用 Fragments/FragmentGroup

2024-01-27

我有一个应用程序,我迫切需要从使用旧的 ActivityGroup 类转换为 Fragments。但我不知道该怎么做。下面是我现在使用的代码示例。谁能提供一些关于我应该采取哪些步骤来开始将其切换为使用 Fragments / FragmentManager 的见解?

主程序.java

public class Main extends TabActivity implements OnTabChangeListener {

    public static TextView txtViewHeading;
    public static Button btnBack;
    public static ImageButton btnShare;
    public static Main mainActivity;
    public static Boolean isVisible = false;
    private GoogleCloudMessaging gcm;
    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;

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

        mainActivity = this;
        NotificationsManager.handleNotifications(this, NotificationSettings.SenderId, PushHandler.class);
        registerWithNotificationHubs();

        //reference headings text & button for access from child activities
        txtViewHeading = (TextView) findViewById(R.id.txtViewHeading);
        btnBack = (Button) findViewById(R.id.btnBack);
        btnShare = (ImageButton) findViewById(R.id.btnShare);

        // Update the font for the heading and back button
        Typeface arialTypeface = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/arial.ttf");
        Typeface myriadTypeface = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/myriad.ttf");
        txtViewHeading.setTypeface(myriadTypeface);
        btnBack.setTypeface(arialTypeface);

        Resources res = getResources();
        TabHost tabsNavigation = getTabHost();

        // Set up the views for each tab - custom view used for Badge icon
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // Set up my tabs...each one looks similar to this
        View statusTabView = inflater.inflate(R.layout.tab, null);
        ImageView statusTabIcon = (ImageView) statusTabView.findViewById(R.id.tabIcon);
        statusTabIcon.setImageResource(R.drawable.tab_first);
        TextView statusTabText = (TextView) statusTabView.findViewById(R.id.tabText);
        statusTabText.setText("Status");
        statusTabText.setTypeface(arialTypeface);
        statusTabBadge = (TextView) statusTabView.findViewById(R.id.tabBadge);
        statusTabBadge.setTypeface(arialTypeface);
        tabsNavigation.addTab(tabsNavigation.newTabSpec(getResources().getString(R.string.main_tab_status))
                .setIndicator(statusTabView)
                .setContent(new Intent(this, StatusGroupActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

        //Set default tab to Status
        tabsNavigation.setCurrentTab(0);
        tabsNavigation.setOnTabChangedListener(this);

    }


    /* Set txtViewHeading text to selected tab text */
    @Override
    public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub
        txtViewHeading.setText(tabId);
    }

    /* Set code to execute when onDestroy method is called */
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }


    /* Set code to execute when onPause method is called */
    @Override
    protected void onPause() {
        super.onPause();
        isVisible = false;
    }

    /* Set code to execute when onResume method is called */
    @Override
    protected void onResume() {
        super.onResume();
        isVisible = true;
    }


    /* Set code to execute when onStop method is called */
    @Override
    protected void onStop() {
        super.onStop();
        isVisible = false;
    }

    /**
     * Check the device to make sure it has the Google Play Services APK. If
     * it doesn't, display a dialog that allows users to download the APK from
     * the Google Play Store or enable it in the device's system settings.
     */
    private boolean checkPlayServices() {
        GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
        int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (apiAvailability.isUserResolvableError(resultCode)) {
                apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                        .show();
            } else {
                ToastNotify("This device is not supported by Google Play Services.");
                finish();
            }
            return false;
        }

        return true;
    }

    public void ToastNotify(final String notificationMessage) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(Main.this, notificationMessage, Toast.LENGTH_LONG).show();
            }
        });
    }

    public void registerWithNotificationHubs()
    {
        if (checkPlayServices()) {
            // Start IntentService to register this application with GCM.
            Intent intent = new Intent(this, RegistrationIntentService.class);
            startService(intent);
        }
    }

}

TabGroupActivity.java

public class TabGroupActivity extends ActivityGroup 
{
    private ArrayList<String> mIdList;
    Button btnBack;
    ImageButton btnShare;
    TextView txtViewHeading;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        btnBack = Main.btnBack;
        btnShare = Main.btnShare;
        txtViewHeading = Main.txtViewHeading;
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        if (mIdList == null) mIdList = new ArrayList<String>();
    }
    /**
     * This is called when a child activity of this one calls its finish method.
     * This implementation calls {@link LocalActivityManager#destroyActivity} on the child activity
     * and starts the previous activity.
     * If the last child activity just called finish(),this activity (the parent),
     * calls finish to finish the entire group.
     */
    @Override
    public void finishFromChild(Activity child) 
    {
        try
        {
            btnShare.setVisibility(View.GONE);
            LocalActivityManager manager = getLocalActivityManager();
            int index = mIdList.size()-1;

            if (index < 1) 
            {
                finish();
                return;
            }

            manager.destroyActivity(mIdList.get(index), true);
            mIdList.remove(index);
            index--;
            String lastId = mIdList.get(index);
            Intent lastIntent = manager.getActivity(lastId).getIntent();
            Window newWindow = manager.startActivity(lastId, lastIntent);           
            setContentView(newWindow.getDecorView());
            //Set Heading text to current Id
            txtViewHeading.setText(getActivityHeading(lastId));     
            //Set Back button text to previous Id if applicable
            btnBack.setVisibility(View.VISIBLE);                
            //Back button
            String backId =  "";
            if(mIdList.size() > 1)
            {
                backId = mIdList.get(mIdList.size()-2);
                btnBack.setVisibility(View.VISIBLE);
                btnBack.setText(getActivityHeading(backId));
                txtViewHeading.setPadding(10,0,0,0);
            }
            else 
            {
                btnBack.setVisibility(View.GONE);
                txtViewHeading.setPadding(0,0,0,0);
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    /**
    * Starts an Activity as a child Activity to this.
    * @param Id Unique identifier of the activity to be started.
    * @param intent The Intent describing the activity to be started.
    */
    public void startChildActivity(String Id, Intent intent) 
    {
        try
        {
            btnShare.setVisibility(View.GONE);
            Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            if (window != null) 
            {
                mIdList.add(Id);
                setContentView(window.getDecorView());
                txtViewHeading.setText(getActivityHeading(Id));
                //Back button
                String backId =  "";
                if(mIdList.size() > 1)
                {
                    backId = mIdList.get(mIdList.size()-2);
                    btnBack.setVisibility(View.VISIBLE);
                    btnBack.setText(backId);
                    txtViewHeading.setPadding(5,0,0,0);
                }
                else 
                {
                    btnBack.setVisibility(View.GONE);
                    txtViewHeading.setPadding(0,0,0,0);
                }                   
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    /**
    * The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
    * from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
    */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if (keyCode == KeyEvent.KEYCODE_BACK) 
        {
            //preventing default
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
    * Overrides the default implementation for KeyEvent.KEYCODE_BACK
    * so that all systems call onBackPressed().
    */
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) 
    {
        if (keyCode == KeyEvent.KEYCODE_BACK) 
        {
            onBackPressed();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    /**
    * If a Child Activity handles KeyEvent.KEYCODE_BACK.
    * Simply override and add this method.
    */
    @Override
    public void onBackPressed () 
    {
        try
        {
            btnShare.setVisibility(View.GONE);
            int length = mIdList.size();
            if ( length > 1) 
            {
                Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
                current.finish();
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }   

    /**
    * Get the correct heading text and language based on activity id
    */
    public String getActivityHeading(String id)
    {
        // method that returns the TEXT for my main heading TextView based on the activity we're on...          
    }               

}

状态组活动

public class StatusGroupActivity extends TabGroupActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("Status", new Intent(this,Status.class));
    }    

}

...所以基本上当我的应用程序加载时,我的选项卡位于底部,标题位于顶部,“选项卡内容”位于中间。在我的状态活动中,我可以通过使用...加载另一个活动

Intent intent = new Intent(getParent(), SomeOtherActivity.class)
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("Some Other Activity", intent);

...并将 SomeOtherActivity 活动加载到内容区域中。回击会将我带回到状态屏幕。

非常感谢任何将其转换为使用片段的指示、示例和帮助。我很乐意捐出 500 美元的代表费。完整示例的要点。

main.xml(主活动布局文件)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    tools:ignore="ContentDescription,HardcodedText" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imageSuccess"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:adjustViewBounds="true"
                android:scaleType="matrix"
                android:src="@drawable/bg_navbar_blank" />

            <com.myproject.android.BgButtonStyle
                android:id="@+id/btnBack"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="0dp"
                android:background="@drawable/back_button"
                android:text=""
                android:textColor="@color/White"
                android:textSize="12sp"
                android:visibility="visible"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:padding="5dp"/>

            <ImageButton
                android:id="@+id/btnShare"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="15dp"
                android:background="@null"
                android:src="@drawable/icon_share"
                android:visibility="visible"
                android:adjustViewBounds="false"
                android:scaleType="fitXY"/>

            <com.myproject.android.AutoResizeTextView
                android:id="@+id/txtViewHeading"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingLeft="5dp"
                android:text="Status"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textSize="28sp"
                android:textStyle="bold"
                android:paddingRight="5dp"
                android:layout_toEndOf="@id/btnBack"
                android:layout_toStartOf="@id/btnShare"
                android:layout_centerVertical="true"
                android:lines="1"/>

        </RelativeLayout>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-4dp"
            android:layout_weight="0"
            android:background="@drawable/bg_tabs">

        </TabWidget>
    </LinearLayout>

</android.support.v4.app.FragmentTabHost>

在我当前的 TabGroupActivity 类中,在 finishFromChild 和 startChildActivity 方法中,我可以在主活动布局中的 txtViewHeading TextView 元素上调用 setText。这是当前活动的“标题”。如果组中有多于 1 个活动,后退按钮将显示上一个标题。我怎样才能在下面的例子中复制这个?那里的主要活动布局和我的有很大不同。


首先你需要添加Design Support Library and AppCompatLibrary进入你的项目

将此代码添加到您的应用程序 gradle 中

compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'

布局为activity_main.xml(就像代码中的 main.xml 一样)

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

在上面的布局中ViewPager将提供水平布局来显示选项卡。您可以使用选项卡在单个屏幕中显示更多屏幕。您可以尽可能快速地滑动选项卡。

根碎片

<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"
android:id="@+id/root_frame" >

查看第一个片段

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ff0"
android:layout_height="match_parent" >

<TextView
    android:id="@+id/tv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:text="@string/first_fragment" />
<Button 
    android:id="@+id/btn"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_width="wrap_content"
    android:text="@string/to_second_fragment"/>

 </RelativeLayout>

查看第二个和单个片段.

<RelativeLayout 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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<TextView
    android:id="@+id/section_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

现在添加一个主要活动(就像您代码中的主要活动),所有这些事情都将在其下处理。

public class MainActivity extends AppCompatActivity {

private TabGroupAdapter mTabGroupAdapter;
private ViewPager mViewPager;

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();
    fragmentList.add(new RootFragment());
    fragmentList.add(new IndividualFragment1());
    fragmentList.add(new IndividualFragment2());
     ArrayList<String> name = new ArrayList<String>() {
        {
            add("Root Tab");
            add("Second Tab");
            add("Third Tab");
        }
    };
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mTabGroupAdapter = new TabGroupAdapter(getSupportFragmentManager(),name, fragmentList,);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mTabGroupAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

}
}

有一个FragmentPagerAdapter定义为mTabGroupAdapter inside MainActivity这将在单个布局中添加不同的选项卡。

首先我们绑定mTabGroupAdapter to mViewPager.

TabLayout会表现得像TabHost在哪个选项卡下将添加FragmentPagerAdapter.

mViewPager绑定到Tablayout.

在主要活动下TabLayout将显示选项卡的名称。

选项卡组适配器

 public class TabGroupAdapter extends FragmentPagerAdapter {

    private ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();
    private ArrayList<String> fragment_name;

    public TabGroupAdapter(FragmentManager fm, ArrayList<String> name, ArrayList<Fragment> list) {
        super(fm);
        this.fragmentList = list;
        this.fragment_name = name;
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return fragment_name.get(position);
    }
}

In TabGroupAdapter你会通过一个List of fragments(or single fragment) and list of fragments name(or single name)作为构造函数中的参数。

IndividualFragment(s)将充当单独的选项卡而不是活动。

RootFragment 将充当其他片段(第一个片段和第二个片段)的容器

根碎片

public  class RootFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.root_fragment, container, false);
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.root_frame, new FirstFragment());
        fragmentTransaction.commit();
        return view;
    }
}

第一个片段

public  class FirstFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.first_fragment, container, false);

        Button btn = (Button) view.findViewById(R.id.btn);

        btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            //use the "root frame" defined in
            //"root_fragment.xml" as the reference to replace fragment
             
            fragmentTransaction.replace(R.id.root_frame, new SecondFragment());
            /*
             * allow to add the fragment 
             * to the stack and return to it later, by pressing back
             */
           fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    });
    }
}

第二个片段

public  class SecondFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        return rootView;
    }
}

个体片段

public  class IndividualFragment1 extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        return rootView;
    }
}



public  class IndividualFragment2 extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        return rootView;
    }
}

In OnCreateView方法你会设​​置一个布局Tab .

您不必使用getTabHost() method.

如果您仍然存在任何问题,请告诉我。

每当您想要动态更改或更新视图寻呼机中的选项卡时,只需添加或删除项目即可fragmentList并调用这个方法mTabGroupAdapter.notifyDataSetChanged(); inside MainActivity.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 ActivityGroup 应用程序转换为使用 Fragments/FragmentGroup 的相关文章

  • 我所有的布局 xml 文件都变成了自动生成的文件

    昨天我的应用程序上的所有内容都运行完美 但今天当我打开 Android Studio 时 所有 xml 文件都已损坏 不确定这是否是正确的术语 每个人都是这样的 我今天遇到了同样的问题 下面是我所做的几个步骤 我取得了成功来解决这个问题 只
  • 键入时将编辑文本中的每个单词大写

    我想在打字时将编辑文本中的每个单词大写 My XML
  • 无法解析符号“AndroidJUnit4”

    显然我需要正确的导入语句来解决这个问题 根据文档用于AndroidJUnit4 http developer android com reference android support test runner AndroidJUnit4 h
  • Flutter - 每次应用程序重新启动后保留变量的值

    在我的一页上 我希望我的用户从一个变量上的默认文本开始 codeDialog 然后我希望他们更改该文本 之后他们编写的文本将成为我的新默认文本 遗憾的是我无法让它发挥作用 现在 当我重新启动应用程序并打开该屏幕时 它会重置为null 我认为
  • 如何通过 Android 中的 Google Fit 集成获取用户信息

    我正在将 Google Fit 应用程序集成到 Android 应用程序中 以使用 SENSORS API 和 HISTORY API 跟踪健身数据 获取步数 如何使用该 API 获取用户信息 电子邮件或用户 ID 对你来说完美的例子 这可
  • 如何创建适用于 iPhone、iPad 和 Android 的 Extjs 应用程序?

    有人成功创建了适用于 iPhone iPad 和 Android 的 Extjs 应用程序吗 我知道 Sencha 不支持移动设备上的 Extjs 但我不想创建另一个仅针对移动设备的网站 我不需要奇特的移动界面 只需要基本的功能 我做了一些
  • 未安装 newrelic 的应用程序上出现 NoClassDefFoundError

    我已经使用他们的 Eclipse 指南为我的 Android 应用程序安装了 newrelic 它在该应用程序上运行正常 现在 如果我创建一个简单的 hello world 项目 我将收到 NoClassDefFoundError 我该如何
  • 如何处理应用程序对 3d party 的依赖

    我当前正在开发的应用程序依赖于第三方应用程序 OIFileManager 我的问题是处理这些依赖关系的一般方法是什么 告诉用户解决它 嵌入 3d party apk 如果其许可证允许 自动解决 也许Android市场有相应的系统 没有自动的
  • 在应用程序启动期间更改主题的最快方法

    目前 我确实在我的应用程序中根据用户最后的选择提供了 2 个主题 深色主题和浅色主题 在主要活动启动期间 我将执行以下操作 public class MyFragmentActivity extends FragmentActivity O
  • Android BLE - 如何分块读取大特征值(使用偏移量)?

    我正在使用 Android SDKandroid 蓝牙 and android 蓝牙 le APIs 我想实现一个应用程序 发挥核心作用 并连接到 BLE 外设以读取特征值和描述符 应用程序需要读取的特征值较大 因此需要分块连续读取 我对如
  • AWS MobileHub:重命名 Android / iOS 示例项目

    我是 AWS Mobilehub 的新手 我喜欢它允许我使用 AWS 配置选项创建项目 但是 当我尝试构建应用程序 ios swift android 时 它总是使用我的示例项目作为项目名称 在 AWS 项目的大多数配置设置中 例如使用 c
  • 如何查看Android Asset资源?

    我想检查 assets 文件夹中是否存在文件 我怎样才能做到呢 请帮忙 我向我的应用程序类之一添加了一个辅助方法 我假设 应用程序运行时 资产列表不会更改 the List
  • 使用 Asp.Net 的 GCM 推送通知

    正如您可能已经看到的 Google 正在迁移其推送通知系统 http developer android com guide google gcm c2dm html http developer android com guide goo
  • Android 设备 ID(不是 IMEI)

    我使用命令 adb devices 列出连接的设备 在我的电脑上我得到 附加设备列表 HT9CTP820988 器件 我的问题是 如何以编程方式获取此 id HT9CTP820988 你所看到的adb devices命令是序列号 序列号 创
  • 为什么在回收器视图中滚动后值会消失?

    Data before scrolling Data after scrolling 我的应用程序的问题如上图所示 输入数据后 如果我在将项目添加为可滚动后滚动 数据就会消失 作为进一步的解释 有时输入的数据出现在已添加的其他项目中 为了解
  • Android - 如何合并两个视频

    基本上 我正在寻找一种将两个 mp4 视频文件 在 SD 卡上 组合在一起的方法 更像是在第一个视频的末尾附加第二个视频 我进行了很多搜索 但找不到合适的解决方案 好吧 我根本找不到任何解决方案 所以我的问题是 是否有一个库可以组合 并可能
  • ProGuard 与 Android:java.lang.NoSuchMethodError:android.util.Xml.asAttributeSet

    当 ProGuard 被禁用时 我的应用程序运行正常 启用ProGuard后 应用程序将导出为apk并安装到模拟器中 然后当我在模拟器中运行它时 强制关闭 05 10 11 14 10 582 E AndroidRuntime 759 FA
  • 如何自动更新Android Studio?

    我需要将 Android Studio 更新到 0 9 9 版本 但是当我按 下载 在更新信息对话框上 时 它会将我发送到此处 http developer android com sdk index html http developer
  • 如何更改焦点/按下时图像按钮的色调

    我有一个ImageButton在我的应用程序中 当按钮打开时我需要更改图像的色调pressed focused 我有ImageButton设置为获取其src来自 XML 文件 如下所示
  • Phonegap - cordova 在 Android 和 iOS 设备上延迟且缓慢

    我刚刚开始使用 zend studio 开始我的第一个 PhoneGap 项目 但是 在我构建并部署它之后 该应用程序非常慢 Android 和 iOS 均可 滚动滞后 如果我按下按钮 转到下一页的速度很慢 有什么办法可以提高它的性能吗 提

随机推荐

  • Python 中的 C# Parallel.Foreach 等效项

    我有 96 个 txt 文件需要处理 现在我正在使用 for 循环并一次执行一个 这个过程非常慢 生成的 96 个文件不需要合并 有没有办法让它们并行运行 比如 C 中的 Parallel foreach 当前代码 for src name
  • 如何在行内块元素之间添加空间?

    明确地说 我不想remove内联块元素之间的空间 我想要add it 我想要的是有一个菜单项网格 一行可以有 2 3 或 4 个项目 我希望使用媒体查询来实现 我怎样才能在我的 li 项目之间添加空间 但也有每行左右两侧无边距 填充无法解决
  • 如何显示mysql数据库的图像和描述

    我正在尝试显示图像 然后在图像下显示描述 我得到了图像显示 但我对描述感到困惑 我无法让它发挥作用 在我的代码下面显示图像和描述 Get images from the database query db gt query SELECT F
  • Mysqldump'不被识别为内部或外部命令可操作程序或批处理文件

    我一直在尝试使用任务计划程序创建批处理来备份 MySQL 数据库 FOR F tokens 1 4 DELIMS F IN date T DO set v date F G H FOR F tokens 1 4 DELIMS F IN ti
  • 错误:(35, 24) 错误:在最新的 Glide 中找不到符号方法 crossFade()

    我有一个使用 Glide 3 5 2 的旧项目 下面的工作正常 Glide with context load url override IMAGE SIZE FIX IMAGE SIZE FIX crossFade placeholder
  • Laravel:从视图调用base_controller中定义的函数

    在使用laravel框架时 如何在视图中调用base controller中定义的函数 例如 class Base Controller extends Controller public static function format so
  • 在 EC2 实例内运行的 docker 容器内运行的 Web 服务器响应非常慢

    我有一个 Web 服务器在 AWS EC2 Ubuntu 实例的 docker 容器内运行 当我向 Web 服务器发送请求时 得到响应的速度非常慢 大多数情况下 20 秒以上 尽管响应时间各不相同 但它不会超时 Web 服务器是一个非常轻量
  • iframe 中的 419 页面已过期 Laravel 页面

    我正在打开一个使用开发的页面Laravel 7在 Angular 项目的 iframe 内 页面正在显示记录 但是在创建或更新记录时 页面会抛出 419 错误 我已经更新了 same site gt none 但没有帮助 这两个项目都部署在
  • 边框半径隐藏的溢出在 Chrome 中不起作用

    不确定这是否是 chrome 特定的错误或什么 但是当我在具有边框半径隐藏溢出的父元素上转换子元素时 溢出是可见的 而转换就位 var wrapper document getElementsByClassName wrapper 0 im
  • 在 Sublime Text 3 中运行 Python 调试器 (pdb)

    如何设置 python 调试器 pdb https docs python org 2 library pdb html Sublime Text 3 中的断点 Both 崇高REPL https packagecontrol io pac
  • Rust 中涉及临时对象的销毁顺序

    在 C 中 如果错误 请纠正我 通过常量引用进行的临时绑定应该比它所绑定的表达式寿命更长 我认为 Rust 也是如此 但在两种不同的情况下我得到了两种不同的行为 考虑 struct A impl Drop for A fn drop mut
  • 同时播放多个音轨并进行同步

    最近我在 Audacity 有一个音频项目 其中有多个曲目 它有分开的人声和分开的乐器 我已将每个曲目导出为 WAV 16 位 文件 我有 5 个文件 5 个曲目 所有文件都超过300MB 长度为25分钟 我试图使用媒体播放器同时播放它们
  • 使用Python创建只读pdf文件

    是否有任何 python 模块可以使用它来创建新的 pdf 文件或修改仅具有读取权限的现有 pdf 文件 我想禁用 pdf 文件的 另存为 和 另存为其他格式 DRM 的东西 我不确定这是否可移植 但您可以使用 os chmod impor
  • 如何创建像android google chrome tab一样的android listview

    我需要像这张图片一样创建列表视图 列表视图项目像谷歌浏览器选项卡一样相互重叠 我可以向上或向下移动列表视图项目 任何人都可以告诉我一个好的建议或告诉我示例我应该如何做到这一点 Thanks 你需要一个 iOS 存折风格的组件 比如卡钱包视图
  • 在 Android Eclipse 上设置多个模拟器

    我正在为我的 Android 应用程序运行性能测试 想知道是否可以在 Eclipse 中同时运行多个模拟器 如果是 我该怎么做 创建多个模拟器 更改android项目运行配置 目标为手动选择而不是自动 右键单击 android 项目 gt
  • 将 pandas crosstab 数据框更改为纯表格式:

    我通过以下 pandas 交叉表获得了聚合数据框 但是 我想要这样的列格式 id ymdh A11 A12 A15 A16 如何将原始数据框更改为我想要的格式 Original output dataframe df pd crosstab
  • 使用 LoginView 触发 UpdatePanel 内的按钮

    我有一个 UpdatePanel 里面有一个 LoginView 现在 在 AnonymousTemplate 里面我有一个按钮 btnLogin 问题是触发器标签看不到该按钮 这是代码
  • Invoke-RestMethod 错误:无法发送正文类型

    我正在尝试使用 Invoke RestMethod 从 Freshdesk 获取门票 我收到的错误是 Invoke RestMethod 无法发送具有此动词类型的内容正文 我的函数如下所示 function opentickets Body
  • django-rest-framework POST 上的“此字段是必需的”

    每当我发布到 django rest framework DRF 端点时 我都会不断收到 HTTP 400 Bad Request offeror organization This field is required 回复 但是 考虑到下
  • 将 ActivityGroup 应用程序转换为使用 Fragments/FragmentGroup

    我有一个应用程序 我迫切需要从使用旧的 ActivityGroup 类转换为 Fragments 但我不知道该怎么做 下面是我现在使用的代码示例 谁能提供一些关于我应该采取哪些步骤来开始将其切换为使用 Fragments FragmentM