Git Product home page Git Product logo

Comments (8)

medyo avatar medyo commented on September 28, 2024

Hi @Amaranya,

Could you share with me your code

from android-about-page.

Amaranya avatar Amaranya commented on September 28, 2024

Sure,
Layout:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="activities.About">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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:popupTheme="@style/AppTheme.PopupOverlay" />

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>

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

And code:

import android.support.design.widget.AppBarLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import java.util.Calendar;

import mehdi.sakout.aboutpage.AboutPage;
import mehdi.sakout.aboutpage.Element;

import com.aleskovacic.eventslocator4.R;

public class About extends AppCompatActivity {
private AppBarLayout mAppBarLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_about);


    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);


    setSupportActionBar(toolbar);
    mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);

    ActionBar ab = getSupportActionBar();

    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle("About Us");

    }

    View aboutPage = new AboutPage(this)
            .isRTL(false)
            .setImage(R.mipmap.ic_launcher)
            .addItem(new Element().setTitle("Version 6.2"))
            .addGroup("Connect with us")
            .addEmail("[email protected]")
            .addFacebook("the.medy")
            .addPlayStore("com.ideashower.readitlater.pro")
            .create();

    setContentView(aboutPage);
    
}

I tried to add

    <item name="android:layout_marginTop">?attr/actionBarSize</item>

to styles - it works -layout moves lower, but AppBarLayout still doesn`t appear:(

from android-about-page.

medyo avatar medyo commented on September 28, 2024

Okay,

by calling setContentView(aboutPage); you're telling your app to use the object aboutPage as a content view, which will automatically ignore all previously declared views.

To fix this, you should add aboutPage to an already declared view, like a linearlayout a framelayout ...
See more details at : #66

from android-about-page.

Amaranya avatar Amaranya commented on September 28, 2024

Thank you for answer, but this doesn`t work for me - activity crashes with error:
"java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.addView(android.view.View, int)' on a null object reference"

this is my host view:

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
/>

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

Maybe you know what`s going wrong? I tried tried to change "about-page view position" in
mActivityRoot.addView(aboutPage, 1) from 1 to 0,2,3,4 - nothing works.

from android-about-page.

medyo avatar medyo commented on September 28, 2024

mActivityRoot is null, make sure you set an id for your linealayout view

<LinearLayout 
    android:id="@+id/main_view" ...>
</LinearLayout>

from android-about-page.

Amaranya avatar Amaranya commented on September 28, 2024

oh, sorry, Ive sent not full xml, its layout:

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
/>

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

and in About.java:

setContentView(R.layout.activity_about);

LinearLayout mActivityRoot = ((LinearLayout) findViewById(R.id.about_toolbar));
mActivityRoot.addView(aboutPage, 1);

So, linearLayout R.id.about_toolbar is declared in both xml and class

from android-about-page.

edwinmugendi avatar edwinmugendi commented on September 28, 2024

Use TableLayout and then add the About Page as a view into the TableLayout

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_about);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        if (getSupportActionBar() != null){
            getSupportActionBar().setTitle(getString(R.string.about_sapamacash));
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }//E# if statement

        tableLayout = (TableLayout) findViewById(R.id.aboutLayout);

        String phone = "+254722906835";

        View aboutPage = new AboutPage(this)
                .isRTL(false)
                .setDescription(getString(R.string.about_us_text))
                .addEmail("[email protected]")
                .addItem(getPhoneElement(phone))
                .addWebsite("https://sapamacash.com/")
                .addFacebook("sapamatech")
                .addTwitter("sapamatech")
                .addYoutube("UCV-sIbWJ5HpO0qk6Hp7Sjfw")
                .addItem(getCopyRightsElement())
                .create();

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        aboutPage.setLayoutParams(params);

        tableLayout.addView(aboutPage, 1,params);

    }



<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".ui.activity.AboutActivity"
    android:id="@+id/aboutLayout">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"/>

    </com.google.android.material.appbar.AppBarLayout>

</TableLayout>



from android-about-page.

edwinmugendi avatar edwinmugendi commented on September 28, 2024

Use TableLayout and then add the About Page as a view into the TableLayout

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_about);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        if (getSupportActionBar() != null){
            getSupportActionBar().setTitle(getString(R.string.about_sapamacash));
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }//E# if statement

        tableLayout = (TableLayout) findViewById(R.id.aboutLayout);

        String phone = "+254722906835";

        View aboutPage = new AboutPage(this)
                .isRTL(false)
                .setDescription(getString(R.string.about_us_text))
                .addEmail("[email protected]")
                .addItem(getPhoneElement(phone))
                .addWebsite("https://sapamacash.com/")
                .addFacebook("sapamatech")
                .addTwitter("sapamatech")
                .addYoutube("UCV-sIbWJ5HpO0qk6Hp7Sjfw")
                .addItem(getCopyRightsElement())
                .create();

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        aboutPage.setLayoutParams(params);

        tableLayout.addView(aboutPage, 1,params);

    }



<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".ui.activity.AboutActivity"
    android:id="@+id/aboutLayout">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"/>

    </com.google.android.material.appbar.AppBarLayout>

</TableLayout>



from android-about-page.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.