@iluhamega
Люблю программировать

Как можно сделать справку в приложении?

Всем привет! Мне нужно сделать справку для приложения. Не знаю как подгрузить текстовой файл к проекту в android stuio. У меня есть текстовой файл в папке проекта "raw".
  • Вопрос задан
  • 925 просмотров
Пригласить эксперта
Ответы на вопрос 2
@KaktusTeam
MoneyApp ведение личного бюджета на Android
Добрый день,
Можно открыть поток и считать данные с этого файла так:
Resources resources = getResources(); // если с фрагмента то getActivity().getResources()
InputStream is = resources.openRawResource(R.raw.my_help_file))
Тут доки
Удачи!
Ответ написан
Комментировать
NeiroNx
@NeiroNx
Программист
Я делал диалоговое окно с WebView и подгружал HTML с assets :
public class HelpDialog extends DialogFragment{
        @Override
        public Dialog onCreateDialog(Bundle savedInstanseState){
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            // Get the layout inflater
            LayoutInflater inflater = getActivity().getLayoutInflater();
            @SuppressLint("InflateParams") final View Help = inflater.inflate(R.layout.help, null, false);
            assert Help!=null;
            final WebView helpText = (WebView)Help.findViewById(R.id.helpText);
            helpText.loadUrl("file:///android_asset/"+getString(R.string.help_dir)+"/index.html");
            ImageButton prew = (ImageButton)Help.findViewById(R.id.help_prew);
            ImageButton next = (ImageButton)Help.findViewById(R.id.help_next);
            ImageButton home = (ImageButton)Help.findViewById(R.id.help_home);
            prew.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    helpText.goBack();
                }
            });
            next.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    helpText.goForward();
                }
            });
            home.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    helpText.loadUrl("file:///android_asset/"+getString(R.string.help_dir)+"/index.html");
                }
            });
            // Inflate and set the layout for the dialog
            // Pass null as the parent view because its going in the dialog layout
            builder.setView(Help)
                    // Add action buttons
                    .setPositiveButton(R.string.action_quit, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            HelpDialog.this.getDialog().cancel();
                        }
                    });
            return builder.create();

        }
    }

и код ресурса фрагмента
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/help_prew"
            android:src="@android:drawable/ic_media_previous" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/help_next"
            android:src="@android:drawable/ic_media_next" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/help_home"
            android:src="@android:drawable/ic_menu_help" />
    </LinearLayout>

    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/helpText"
        android:focusableInTouchMode="false" />
</LinearLayout>


Вывод на экран так:
DialogFragment help = new HelpDialog();
                help.show(getSupportFragmentManager(),"help");
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы