Maniruzzaman Akash's Blog

Maniruzzaman Akash, A programmer, A web programmer, a helpful person to share knowledge and everything..

  • Home
  • Programming
    • C Programming
    • Java Programming
    • C++ Programming
    • C# Programming
    • Python Programming
    • Data Structure
  • Web
    • HTML
    • CSS
    • Javascript
    • PHP
    • AJAX
    • XML
  • FrameWork
    • Bootstrap(CSS)
    • Laravel 5(PHP)
  • Database
    • MySQL
    • Oracle
    • SQL Server
  • Android
    • Android Development
  • Mathematics
    • Numerical Methods
  • Others
    • My Articles
    • Download Ebooks
    • Mathematics
    • Difference Between
  • Contact
Showing posts with label Android Developement. Show all posts
Android Developement

How to add custom xml background for button or layout in android studio

Saturday, April 22, 2017 By Maniruzzaman Akash 0 Comments

Problem :

And Custom background for my button, layout, textview, edittext and for all. This is a very nice look if you can add a custom background on your button. Suppose when someone click your android button it will be different background color or text color or any image.


Solution:

First in your android app/res/drawable/ folder add alert_button.xml file which will contain the following code:

-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="#FF0000"
                android:endColor="#FF1223"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#dcdcdc" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <gradient
                android:startColor="#ffc2b7"
                android:endColor="#ffc2b7"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#dcdcdc" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="@color/red_deep"
                android:endColor="@color/red_light"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#A6A6A6" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>
-------------------------------------------
You have done the most part of your custom xml background for you simple button.
Now in activity.xml file use it by this way,

-------------------------------------------
<Button
 android:text="Reset"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="right"
 android:background="@drawable/alert_button"
 android:textColor="@color/white"
 android:textStyle="bold"
 android:id="@+id/btn_reset"
 android:gravity="center" 
/>
-------------------------------------------

And you have completed your work and see the result. I think that more awesome and pretty. In my case this is look like this when I'm clicking/pressed on the button

Now See precious look is(Reset Button is little dark):

Now See after applying the code and clicking on Reset Button (It is now more dark red as our defined style from XML):


Code Explanation:

Now come to code explanation, it is a very simple code. To add a condition for pressed state just make an item inside <selector>...</selector>
<item android:state_pressed="true" >

Then, inside <shape> just add the pressed color. We have to set two color Just do this:
<gradient
  android:startColor="#FF0000"
  android:endColor="#FF1223"
  android:angle="270" 
/>

And without any state that means when no click,pressed, focused the code will look like this:

<item>
        <shape>
            <gradient
                android:startColor="@color/red_deep"
                android:endColor="@color/red_light"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#A6A6A6" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

In this case additional padding is just for beautify.
I think all is clear to you now, Happy coding with android...
Continue reading
Share:
Views:
Android Developement

How to solve all starting problems of android studio

Tuesday, February 7, 2017 By Maniruzzaman Akash 1 Comments
This tutorial is all about How to solve all starting problems of android studio.
This is a simple step and provable the best and easy step even made.

Android Studio Problems:

  1. R can not be resolved to a variable :
  2. junit:junit:..... errors :
  3. javax... errors :
  4. sdk errors :
Solution:

Sometimes when starting any android project can't work perfectly in your computer. In that case you may be see the errors and can't solve these problems. And I've found a great solutions for all of these problems.

First If everything not Ok, then just open your Internet connection and click Sync Now and after a minute all necessary plugins will be installed from internet and your app won't see any error. 

So, if you only Sync then, it may not work but if you connect your PC to internet your all problems will be solved quickly and its guaranteed.

Since, if you face any problem, comment please and I'll try to help you.
Continue reading
Share:
Views:
Android Developement

How to make a simple android text to speech converter app

Thursday, February 2, 2017 By Maniruzzaman Akash 0 Comments
In this tutorial, I'll show you how to make a simple android app of  text to speech converter on some languages..

Let's create a android project called Text2Speech with MainActivity.

App is look like this->




And in res/layout folder activity_main.xml file is:

<LinearLayout 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:orientation="vertical"

    tools:context=".MainActivity" >



    <TextView

        android:id="@+id/textView1"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:background="#ccc"

        android:gravity="center"

        android:padding="10sp"

        android:text="@string/textView_text"

        android:textSize="20sp" />



    <EditText

        android:id="@+id/edtxt_write"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:hint="@string/write_text"

         />



    <Button

        android:id="@+id/btnListen"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_gravity="center"

        android:background="#5ba"

        android:ellipsize="end"

        android:gravity="center"

        android:text="@string/listen_text" />



</LinearLayout>




And for that Output is look like the above image of app.
For the layout file in res/valuesfolder strings.xml file is:

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

<resources>



    <string name="app_name">Text 2 Speech</string>

    <string name="hello_world">Hello world!</string>

    <string name="menu_settings">Settings</string>

    <string name="menu_exit">Exit</string>

    <string name="listen_text">Listen Now</string>

    <string name="write_text">Write your text here..</string>

    <string name="textView_text">Write your text in the edit text to speech..</string>

   



</resources>




And now our layout is complete for android text to speech converter apps.Now go to coding in src/package../MainActivity.java code is:

package com.akash.text2speech;



import java.util.Locale;



import org.w3c.dom.Text;



import android.os.Bundle;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.Context;

import android.content.DialogInterface;

import android.speech.tts.TextToSpeech;

import android.speech.tts.TextToSpeech.OnInitListener;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.inputmethod.InputMethodManager;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;



public class MainActivity extends Activity {

 

 EditText editextWrite;

 Button btnListenNow;

 

 private TextToSpeech speech;



 @Override

 protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);



  editextWrite = (EditText) findViewById(R.id.edtxt_write);

  btnListenNow = (Button) findViewById(R.id.btnListen);

  

  //Setup speech object

  speech = new TextToSpeech(getApplicationContext(), new OnInitListener() {

   

   @Override

   public void onInit(int status) {

    if (status != TextToSpeech.ERROR) {

     speech.setLanguage(Locale.UK);

    }

   }

  });

  

  btnListenNow.setOnClickListener(new OnClickListener() {

   

   @Override

   public void onClick(View arg0) {

    

    // Hide Keyboad from display

    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    inputMethodManager.hideSoftInputFromWindow(editextWrite.getWindowToken(), 0);

    

    String Speak = editextWrite.getText().toString();

    Toast.makeText(getApplicationContext(), "Speaking Text is : "+Speak, Toast.LENGTH_LONG).show();

    speech.speak(Speak, TextToSpeech.QUEUE_FLUSH, null);

    

   }

  });

 }



 @Override

 protected void onPause() {

  if (speech != null) {

   speech.stop();

   speech.shutdown();

  }

  super.onPause();

 }

 

 @Override

 public void onBackPressed() {

  exitAlert();

 }

 

 @Override

 public boolean onCreateOptionsMenu(Menu menu) {

  // Inflate the menu; this adds items to the action bar if it is present.

  getMenuInflater().inflate(R.menu.activity_main, menu);

  return true;

 }

 

 @Override

 public boolean onOptionsItemSelected(MenuItem item) {



  int id = item.getItemId();

  if (id == R.id.menu_exit) {

   exitAlert();

  }

  

  

  return super.onOptionsItemSelected(item);

 }

 

 /**

  * Exit Alert Function

  *

  * @return void -> Make an exit Alert

  */

 public void exitAlert() {

  AlertDialog.Builder alertBuilder =new AlertDialog.Builder(MainActivity.this);

  alertBuilder.setTitle("Warning");

  alertBuilder.setMessage("Do you want to close the app?");

  alertBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

   

   @Override

   public void onClick(DialogInterface arg0, int arg1) {

    finish();

   }

  });

  alertBuilder.setNegativeButton("No", null);

  alertBuilder.show();

 }



}


And our Manifest.xml file is:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.akash.text2speech"

    android:versionCode="1"

    android:versionName="1.0" >



    <uses-sdk

        android:minSdkVersion="11"

        android:targetSdkVersion="17" />

    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name="com.akash.text2speech.MainActivity"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>



</manifest>


Now starting to code demonstration:
in this line
import android.speech.tts.TextToSpeech;
we import TextToSpeech class of android which convert text to speech.

In this line,
 private TextToSpeech speech;
Create a TextToSpeech object named speech for future reuse it.

And in this line we initialize the speech object and start it, just simple code:
  //Setup speech object

  speech = new TextToSpeech(getApplicationContext(), new OnInitListener() {

   

   @Override

   public void onInit(int status) {

    if (status != TextToSpeech.ERROR) {

     speech.setLanguage(Locale.UK);

    }

   }

  });


In this line of code create Initializing listener to initiate the TextToSpeech class and we have set language to UK in this line-
speech.setLanguage(Locale.UK);
You cans set some other built in language and check that also pressing control+space.

And when onclick the button just start the speech
   @Override

   public void onClick(View arg0) {

    

    // Hide Keyboad from display

    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    inputMethodManager.hideSoftInputFromWindow(editextWrite.getWindowToken(), 0);

    

    String Speak = editextWrite.getText().toString();

    Toast.makeText(getApplicationContext(), "Speaking Text is : "+Speak, Toast.LENGTH_LONG).show();

    speech.speak(Speak, TextToSpeech.QUEUE_FLUSH, null);

    

   }
First hide the keyboard from the apps and then make a Speak string which will be retrieved from the edittext, then in this line:
speech.speak(Speak, TextToSpeech.QUEUE_FLUSH, null);
.QUEUE_FLUSH function makes the speech and takes its as a queue of every letter and just make a flush sound of that word.
We can learn more about the function in android developer site.

Thats all of this simple android text to speech converter app. And other thing is the same as all of the apps that means when backpressed an alert dialog will be open to saying if you want to exit or not.

You can download this android text to speech converter app from dropbox. If any advertise occur, please click Skip add
Download source code:





Continue reading
Share:
Views:
Android Developement

R can not be resolved to a variable android studio problem solution..100% working

Saturday, January 28, 2017 By Maniruzzaman Akash 0 Comments
R can not be resolved to a variable is a big problem for the beginner level programmer of android and for that reason while coding, I've got few solutions of this problem R can not be resolved to a variable.
And for that I've written a a solution in Stack overflow. You can also read that in this URL:.
http://stackoverflow.com/questions/34979903/android-studio-gradle-build-problems-r-cant-be-resolved/41780229#41780229.

So, come to the problem of R can not be resolved to a variable.


Why this happen:

R can not be resolved to a variable is a resource file problem, that means when we run any app, then it automatically make code for all graphical representation. Reasons of this is:

  1. When there is an error in your .xml file and it will not show an error in that file but for this reason sometime occur R can not be resolved to a variable problem in Activity.java files...
  2. .Sometimes there are problem in theme choosing matters.

Solutions of R can not be resolved to a variable:

  1. Look, if you don't write any code in .xml file then just click rebuild or build or make project button or clean button. Your problem may be solved if you have not write any code previously.
  2. If you modify your xxxxx.xml layout file then look these files and I'm sure you've written some wrong code. Like theme name problem, any referencing problem of strings, dimens, colors and so on. Correct them and may be your R can't be resolved text will be solved. Obviously, after doing this click make project button or rebuild button and provably get no error..

Look in my demo case of this problem R can not be resolved to a variable.
In my styles.xml file I have written that:

<style name="MyCustomToolbar" parent="ThemeOverlay.AppCompat.Light">
    <item name="colorPrimary">#5974AB</item>
</style>
And in my main layout.xml file I have written that:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
....
android:popupTheme="@style/MyCustomToolber"
>

</android.support.v7.widget.Toolbar>
Look this line of layout.xml:
android:popupTheme="@style/MyCustomToolber"
I've write some wrong name that means name mismatched..And for that reason there was a problem in my xml file of R can not be resolved to variable..

And finally if you face any problem then knock me here and I 'll answer obviously...


Continue reading
Share:
Views:
Android Developement Download Ebook

Download android 3D game development ebook

Wednesday, November 30, 2016 By Maniruzzaman Akash 0 Comments
Android 3D game development is the development of your android game programming. It'll may be start when you've completed some basic level of android development, like make a simple free app, a database connected app etc etc.






Book name                 : Android 3D game development [Beginner]
Author                        : Robert Chinn
Published By              : Apress


Apress has published all of the greatest books of programming. In this book you can learn how to make a 3d game and finally you can make a mini game project using 3D calculations and programming.

Game will be like this-




And obviously this will be a great starting in android 3d game development programming study. So, download the book now. And from apress or amazon I'd bought this book at $29. And now it's free for you. Reason- My vision is to share everything with each other and then our earth will be a great place.

Download the book 
[Note: If any add happen, please click skip and download it from Dropbox]
Download the book
[Note: If any add happen, please click skip and download it from Dropbox]
Download the book
[Note: If any add happen, please click skip and download it from Dropbox]
Download the book
[Note: If any add happen, please click skip and download it from Dropbox]


If you face any problem to downloading or understanding any code in this book, comment here and I think we can solve together.
Continue reading
Share:
Views:
Older Posts Home
Subscribe to: Posts ( Atom )

Popular Posts

  • Numerical Methods 20 Multiple Choice Questions and Answers
  • Consider a hypothetical 32-bit microprocessor having 32-bit instructions: Solutions
  • List and briefly define two approaches to dealing with multiple interrupts
  • The hypothetical machine has two I/O instructions: 0011= Load AC fro I/O 0111= Store AC to I/O Solutions
  • What are the characteristics of Digital IC's?-Solution
  • Mid Square Method Code implementation in C and MatLab
  • List and briefly define the possible states that define an instruction execution
  • BFS, DFS, DLS in Tree implementation in C
  • Download Laravel Offline Documentation as HTML
  • Simpson's 1/3 Code in Matlab

Category

Advanced PHP Android Developement Articles Artificial Intelligenece Blogger Tips Blogging Career Bootstrap Offline Documentation Bootstrap Templates C Programming Computer Architecture Data Structure Difference Between Download Documentation Download Ebook Download Free Blog Template Earning Money Electrical Electronics Guest Posts HTML Java Programming Laravel Laravel Bangla Tutorial MatLab Code My Videos MySQL Database Numerical Methods Offline Documentation Recent Topics Simulation and Modeling Unity Game Development Web Design Web Development

LIKE ME ON FACEBOOK

TAGS

  • Advanced PHP (3)
  • Android Developement (5)
  • Articles (6)
  • Artificial Intelligenece (3)
  • Blogger Tips (5)
  • Blogging Career (1)
  • Bootstrap Offline Documentation (1)
  • Bootstrap Templates (1)
  • C Programming (14)
  • Computer Architecture (5)
  • Data Structure (11)
  • Difference Between (1)
  • Download Documentation (2)
  • Download Ebook (3)
  • Download Free Blog Template (2)
  • Earning Money (1)
  • Electrical Electronics (1)
  • Guest Posts (1)
  • HTML (4)
  • Java Programming (2)
  • Laravel (3)
  • Laravel Bangla Tutorial (1)
  • MatLab Code (2)
  • My Videos (3)
  • MySQL Database (7)
  • Numerical Methods (9)
  • Offline Documentation (1)
  • Recent Topics (1)
  • Simulation and Modeling (2)
  • Unity Game Development (3)
  • Web Design (3)
  • Web Development (1)

Join Google+

Maniruzzaman Akash
View my complete profile

Join With Me

Site Visitors

Best Sites For a programmer

  • URI Online Judge Solution By Me
  • StackOverFlow
  • W3 School
  • Git Hub - Store your Every Document

Popular Posts

  • ফিফা ওয়ার্ল্ড কাপ ২০১৮ শিডিউল এবং সমস্ত আপডেট- FIFA World Cup 2018 - Bangladesh Time Schedule
  • How to import Excel,CSV file in Laravel And insert data in database
  • Download 20 responsive Free E-Commerce Template 2017
  • What are the characteristics of Digital IC's?-Solution
  • Mid Square Method Code implementation in C and MatLab
  • The hypothetical machine has two I/O instructions: 0011= Load AC fro I/O 0111= Store AC to I/O Solutions
  • Consider a hypothetical 32-bit microprocessor having 32-bit instructions: Solutions
  • ‘Do My Assignment for Me’ Orders: All Kinds of Difficult Projects Done with Ease
  • Download Tutorials point offline documentation latest version 2017 - Free Tutorials point documentation full
  • List and briefly define two approaches to dealing with multiple interrupts

Earn Money From Your site

Translate To your language

Categories

Advanced PHP (3) Android Developement (5) Articles (6) Artificial Intelligenece (3) Blogger Tips (5) Blogging Career (1) Bootstrap Offline Documentation (1) Bootstrap Templates (1) C Programming (14) Computer Architecture (5) Data Structure (11) Difference Between (1) Download Documentation (2) Download Ebook (3) Download Free Blog Template (2) Earning Money (1) Electrical Electronics (1) Guest Posts (1) HTML (4) Java Programming (2) Laravel (3) Laravel Bangla Tutorial (1) MatLab Code (2) My Videos (3) MySQL Database (7) Numerical Methods (9) Offline Documentation (1) Recent Topics (1) Simulation and Modeling (2) Unity Game Development (3) Web Design (3) Web Development (1)

Subscribe To This Site To Get Latest Article On Programming or web

Posts
Atom
Posts
All Comments
Atom
All Comments
© 2016 Maniruzzaman Akash's Blog | All rights reserved
Developed By Maniruzzaman Akash Created By Responsive Blogger Templates | Distributed By Gooyaabi Templates